You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2006/07/28 10:22:55 UTC
svn commit: r426431 [12/14] - in /incubator/activemq/branches/activemq-4.0:
activemq-core/src/gram/script/
activemq-core/src/main/java/org/apache/activemq/kaha/impl/
activemq-core/src/main/java/org/apache/activemq/openwire/v1/
activemq-core/src/test/ja...
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ISocket.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ISocket.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ISocket.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ISocket.hpp Fri Jul 28 01:22:48 2006
@@ -1,68 +1,68 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_ISocket_hpp_
-#define Ppr_ISocket_hpp_
-
-#include "ppr/net/SocketException.hpp"
-#include "ppr/util/ifr/p"
-
-namespace apache
-{
- namespace ppr
- {
- namespace net
- {
- using namespace ifr;
-
-/*
- *
- */
-struct ISocket : Interface
-{
- /**
- */
- virtual void connect(const char* host, int port) throw (SocketException) = 0 ;
- /**
- */
- virtual void setSoTimeout(int millisecs) throw (SocketException) = 0;
- /**
- */
- virtual int getSoTimeout() const = 0;
- /**
- */
- virtual int receive(char* buff, int size) throw (SocketException) = 0;
- /**
- */
- virtual int send(const unsigned char* buff, int size) throw (SocketException) = 0;
- /**
- */
- virtual int send(const char* buff, int size) throw (SocketException) = 0;
- /**
- */
- virtual void close() = 0;
- /**
- */
- virtual bool isConnected() const = 0;
-};
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_ISocket_hpp_*/
-
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_ISocket_hpp_
+#define Ppr_ISocket_hpp_
+
+#include "ppr/net/SocketException.hpp"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace net
+ {
+ using namespace ifr;
+
+/*
+ *
+ */
+struct ISocket : Interface
+{
+ /**
+ */
+ virtual void connect(const char* host, int port) throw (SocketException) = 0 ;
+ /**
+ */
+ virtual void setSoTimeout(int millisecs) throw (SocketException) = 0;
+ /**
+ */
+ virtual int getSoTimeout() const = 0;
+ /**
+ */
+ virtual int receive(char* buff, int size) throw (SocketException) = 0;
+ /**
+ */
+ virtual int send(const unsigned char* buff, int size) throw (SocketException) = 0;
+ /**
+ */
+ virtual int send(const char* buff, int size) throw (SocketException) = 0;
+ /**
+ */
+ virtual void close() = 0;
+ /**
+ */
+ virtual bool isConnected() const = 0;
+};
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_ISocket_hpp_*/
+
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ISocket.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ISocketFactory.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ISocketFactory.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ISocketFactory.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ISocketFactory.hpp Fri Jul 28 01:22:48 2006
@@ -1,46 +1,46 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_ISocketFactory_hpp_
-#define Ppr_ISocketFactory_hpp_
-
-#include "ISocket.hpp"
-
-namespace apache
-{
- namespace ppr
- {
- namespace net
- {
- using namespace ifr;
-
-/*
- *
- */
-struct ISocketFactory : Interface
-{
- /** Creates an unconnected socket ready to call connect() on.
- */
- virtual p<ISocket> createSocket() = 0 ;
-} ;
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_ISocketFactory_hpp_*/
-
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_ISocketFactory_hpp_
+#define Ppr_ISocketFactory_hpp_
+
+#include "ISocket.hpp"
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace net
+ {
+ using namespace ifr;
+
+/*
+ *
+ */
+struct ISocketFactory : Interface
+{
+ /** Creates an unconnected socket ready to call connect() on.
+ */
+ virtual p<ISocket> createSocket() = 0 ;
+} ;
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_ISocketFactory_hpp_*/
+
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ISocketFactory.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.cpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.cpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.cpp Fri Jul 28 01:22:48 2006
@@ -1,158 +1,158 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifdef unix
-#include <unistd.h>
-#include <netdb.h>
-#include <fcntl.h>
-#include <sys/file.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#else
-#include <Winsock2.h>
-#include <Ws2tcpip.h>
-#include <sys/stat.h>
-#define stat _stat
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <ctype.h>
-#include <errno.h>
-#include <sys/types.h>
-#include "ppr/net/ServerSocket.hpp"
-
-using namespace apache::ppr::net;
-
-inline int SOCKETclose( Socket::SocketHandle sock )
-{
-#ifdef unix
- return ::close(sock);
-#else
- return ::closesocket(sock);
-#endif
-}
-
-ServerSocket::ServerSocket() : socketHandle (Socket::INVALID_SOCKET_HANDLE)
-{
-#ifndef unix
- if( Socket::staticSocketInitializer.getSocketInitError() != NULL )
- throw *Socket::staticSocketInitializer.getSocketInitError();
-#endif
-}
-
-ServerSocket::~ServerSocket()
-{
- if( isBound() )
- {
- // No shutdown, just close - dont want blocking destructor.
- SOCKETclose (socketHandle);
- }
-}
-
-void ServerSocket::bind (const char* host, int port) throw (SocketException)
-{
- bind(host, port, SOMAXCONN);
-}
-
-void ServerSocket::bind (const char* host, int port, int backlog) throw (SocketException)
-{
- SocketHandle listen_socket_handle;
- int ret ;
-
- if( isBound() )
- throw SocketException ("Socket already bound") ;
-
- listen_socket_handle = ::socket(AF_INET, SOCK_STREAM, 0) ;
-
- if( listen_socket_handle < 0 )
- throw SocketException ("Could not create socket");
-
- if( port <= 0 || port > 65535 )
- throw SocketException ("Port out of range");
-
- sockaddr_in bind_addr;
- bind_addr.sin_family = AF_INET;
- bind_addr.sin_port = htons((short)port);
- bind_addr.sin_addr.s_addr = 0; // To be set later down...
- memset(&bind_addr.sin_zero, 0, sizeof(bind_addr.sin_zero));
-
- // Resolve name
- ::addrinfo hints;
- memset(&hints, 0, sizeof(addrinfo));
- hints.ai_family = PF_INET;
- struct addrinfo *res_ptr = NULL;
-
- if( ::getaddrinfo(host, NULL, &hints, &res_ptr) != 0 || res_ptr == NULL )
- throw SocketException ("Could not resolve name");
- else
- {
- assert(res_ptr->ai_addr->sa_family == AF_INET);
- // Porting: On both 32bit and 64 bit systems that we compile to soo far, sin_addr is a 32 bit value, not an unsigned long.
- assert(sizeof(((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr) == 4);
- bind_addr.sin_addr.s_addr = ((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr;
- freeaddrinfo(res_ptr);
- }
-
- ret = ::bind(listen_socket_handle,
- (sockaddr *)&bind_addr, sizeof(bind_addr));
-
- if( ret < 0 )
- {
- SOCKETclose (listen_socket_handle);
- throw SocketException ("Could not bind");
- }
- ret = ::listen(listen_socket_handle, backlog);
- if( ret < 0 )
- {
- SOCKETclose (listen_socket_handle);
- throw SocketException ("Could not listen");
- }
- socketHandle = listen_socket_handle;
-}
-
-void ServerSocket::close ()
-{
- if( isBound() )
- {
- SOCKETclose (this->socketHandle);
- this->socketHandle = Socket::INVALID_SOCKET_HANDLE;
- }
-}
-
-bool ServerSocket::isBound() const
-{
- return this->socketHandle != Socket::INVALID_SOCKET_HANDLE;
-}
-
-p<ISocket> ServerSocket::accept () throw (SocketException)
-{
- struct sockaddr_in temp;
-#ifdef unix
- socklen_t temp_len = sizeof (sockaddr_in);
-#else
- int temp_len = sizeof (sockaddr_in);
-#endif
- SocketHandle ss_socket_handle = Socket::INVALID_SOCKET_HANDLE;
-
- ss_socket_handle = ::accept(this->socketHandle, (struct sockaddr*)&temp, &temp_len);
- if (ss_socket_handle < 0) {
- throw SocketException ("Accept Error");
- }
- return new Socket (ss_socket_handle);
-}
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifdef unix
+#include <unistd.h>
+#include <netdb.h>
+#include <fcntl.h>
+#include <sys/file.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#else
+#include <Winsock2.h>
+#include <Ws2tcpip.h>
+#include <sys/stat.h>
+#define stat _stat
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <errno.h>
+#include <sys/types.h>
+#include "ppr/net/ServerSocket.hpp"
+
+using namespace apache::ppr::net;
+
+inline int SOCKETclose( Socket::SocketHandle sock )
+{
+#ifdef unix
+ return ::close(sock);
+#else
+ return ::closesocket(sock);
+#endif
+}
+
+ServerSocket::ServerSocket() : socketHandle (Socket::INVALID_SOCKET_HANDLE)
+{
+#ifndef unix
+ if( Socket::staticSocketInitializer.getSocketInitError() != NULL )
+ throw *Socket::staticSocketInitializer.getSocketInitError();
+#endif
+}
+
+ServerSocket::~ServerSocket()
+{
+ if( isBound() )
+ {
+ // No shutdown, just close - dont want blocking destructor.
+ SOCKETclose (socketHandle);
+ }
+}
+
+void ServerSocket::bind (const char* host, int port) throw (SocketException)
+{
+ bind(host, port, SOMAXCONN);
+}
+
+void ServerSocket::bind (const char* host, int port, int backlog) throw (SocketException)
+{
+ SocketHandle listen_socket_handle;
+ int ret ;
+
+ if( isBound() )
+ throw SocketException ("Socket already bound") ;
+
+ listen_socket_handle = ::socket(AF_INET, SOCK_STREAM, 0) ;
+
+ if( listen_socket_handle < 0 )
+ throw SocketException ("Could not create socket");
+
+ if( port <= 0 || port > 65535 )
+ throw SocketException ("Port out of range");
+
+ sockaddr_in bind_addr;
+ bind_addr.sin_family = AF_INET;
+ bind_addr.sin_port = htons((short)port);
+ bind_addr.sin_addr.s_addr = 0; // To be set later down...
+ memset(&bind_addr.sin_zero, 0, sizeof(bind_addr.sin_zero));
+
+ // Resolve name
+ ::addrinfo hints;
+ memset(&hints, 0, sizeof(addrinfo));
+ hints.ai_family = PF_INET;
+ struct addrinfo *res_ptr = NULL;
+
+ if( ::getaddrinfo(host, NULL, &hints, &res_ptr) != 0 || res_ptr == NULL )
+ throw SocketException ("Could not resolve name");
+ else
+ {
+ assert(res_ptr->ai_addr->sa_family == AF_INET);
+ // Porting: On both 32bit and 64 bit systems that we compile to soo far, sin_addr is a 32 bit value, not an unsigned long.
+ assert(sizeof(((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr) == 4);
+ bind_addr.sin_addr.s_addr = ((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr;
+ freeaddrinfo(res_ptr);
+ }
+
+ ret = ::bind(listen_socket_handle,
+ (sockaddr *)&bind_addr, sizeof(bind_addr));
+
+ if( ret < 0 )
+ {
+ SOCKETclose (listen_socket_handle);
+ throw SocketException ("Could not bind");
+ }
+ ret = ::listen(listen_socket_handle, backlog);
+ if( ret < 0 )
+ {
+ SOCKETclose (listen_socket_handle);
+ throw SocketException ("Could not listen");
+ }
+ socketHandle = listen_socket_handle;
+}
+
+void ServerSocket::close ()
+{
+ if( isBound() )
+ {
+ SOCKETclose (this->socketHandle);
+ this->socketHandle = Socket::INVALID_SOCKET_HANDLE;
+ }
+}
+
+bool ServerSocket::isBound() const
+{
+ return this->socketHandle != Socket::INVALID_SOCKET_HANDLE;
+}
+
+p<ISocket> ServerSocket::accept () throw (SocketException)
+{
+ struct sockaddr_in temp;
+#ifdef unix
+ socklen_t temp_len = sizeof (sockaddr_in);
+#else
+ int temp_len = sizeof (sockaddr_in);
+#endif
+ SocketHandle ss_socket_handle = Socket::INVALID_SOCKET_HANDLE;
+
+ ss_socket_handle = ::accept(this->socketHandle, (struct sockaddr*)&temp, &temp_len);
+ if (ss_socket_handle < 0) {
+ throw SocketException ("Accept Error");
+ }
+ return new Socket (ss_socket_handle);
+}
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.hpp Fri Jul 28 01:22:48 2006
@@ -1,84 +1,84 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_ServerSocket_hpp_
-#define Ppr_ServerSocket_hpp_
-
-#include "ppr/net/IServerSocket.hpp"
-#include "ppr/net/Socket.hpp"
-
-namespace apache
-{
- namespace ppr
- {
- namespace net
- {
- using namespace ifr;
-
-/*
- *
- */
-class ServerSocket : public IServerSocket
-{
-public:
- typedef Socket::SocketHandle SocketHandle;
-private:
- SocketHandle socketHandle;
-public:
- /** Constructor.
- Creates a non-bound server socket.
- */
- ServerSocket();
-
- /** Destructor.
- Releases socket handle if close() hasn't been called.
- */
- virtual ~ServerSocket();
-public:
- /** Bind and listen to given IP/dns and port.
- @param host IP address or host name.
- @param port TCP port between 1..655535
- */
- virtual void bind (const char* host, int port) throw (SocketException);
-
- /** Bind and listen to given IP/dns and port.
- @param host IP address or host name.
- @param port TCP port between 1..655535
- @param backlog Size of listen backlog.
- */
- virtual void bind (const char* host, int port, int backlog) throw (SocketException);
-
- /** Blocks until a client connects to the bound socket.
- @return new socket. Never returns NULL.
- */
- virtual p<ISocket> accept () throw (SocketException);
-
- /** Closes the server socket.
- */
- virtual void close();
-
- /** @return true of the server socket is bound.
- */
- virtual bool isBound() const;
-};
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_ServerSocket_hpp_*/
-
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_ServerSocket_hpp_
+#define Ppr_ServerSocket_hpp_
+
+#include "ppr/net/IServerSocket.hpp"
+#include "ppr/net/Socket.hpp"
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace net
+ {
+ using namespace ifr;
+
+/*
+ *
+ */
+class ServerSocket : public IServerSocket
+{
+public:
+ typedef Socket::SocketHandle SocketHandle;
+private:
+ SocketHandle socketHandle;
+public:
+ /** Constructor.
+ Creates a non-bound server socket.
+ */
+ ServerSocket();
+
+ /** Destructor.
+ Releases socket handle if close() hasn't been called.
+ */
+ virtual ~ServerSocket();
+public:
+ /** Bind and listen to given IP/dns and port.
+ @param host IP address or host name.
+ @param port TCP port between 1..655535
+ */
+ virtual void bind (const char* host, int port) throw (SocketException);
+
+ /** Bind and listen to given IP/dns and port.
+ @param host IP address or host name.
+ @param port TCP port between 1..655535
+ @param backlog Size of listen backlog.
+ */
+ virtual void bind (const char* host, int port, int backlog) throw (SocketException);
+
+ /** Blocks until a client connects to the bound socket.
+ @return new socket. Never returns NULL.
+ */
+ virtual p<ISocket> accept () throw (SocketException);
+
+ /** Closes the server socket.
+ */
+ virtual void close();
+
+ /** @return true of the server socket is bound.
+ */
+ virtual bool isBound() const;
+};
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_ServerSocket_hpp_*/
+
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocketFactory.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocketFactory.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocketFactory.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocketFactory.hpp Fri Jul 28 01:22:48 2006
@@ -1,50 +1,50 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_ServerSocketFactory_hpp_
-#define Ppr_ServerSocketFactory_hpp_
-
-#include "ppr/net/IServerSocketFactory.hpp"
-#include "ppr/net/ServerSocket.hpp"
-
-namespace apache
-{
- namespace ppr
- {
- namespace net
- {
- using namespace std;
-
-/*
- *
- */
-class ServerSocketFactory : public IServerSocketFactory
-{
-public:
- /** Creates an unbound TCP/IP server socket, ready to call bind() on.
- */
- virtual p<IServerSocket> createSocket() {
- return new ServerSocket();
- }
-};
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_ServerSocketFactory_hpp_*/
-
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_ServerSocketFactory_hpp_
+#define Ppr_ServerSocketFactory_hpp_
+
+#include "ppr/net/IServerSocketFactory.hpp"
+#include "ppr/net/ServerSocket.hpp"
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace net
+ {
+ using namespace std;
+
+/*
+ *
+ */
+class ServerSocketFactory : public IServerSocketFactory
+{
+public:
+ /** Creates an unbound TCP/IP server socket, ready to call bind() on.
+ */
+ virtual p<IServerSocket> createSocket() {
+ return new ServerSocket();
+ }
+};
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_ServerSocketFactory_hpp_*/
+
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/ServerSocketFactory.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Socket.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Socket.cpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Socket.cpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Socket.cpp Fri Jul 28 01:22:48 2006
@@ -1,293 +1,293 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifdef unix
-#include <unistd.h>
-#include <netdb.h>
-#include <fcntl.h>
-#include <sys/file.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#else
-#include <Winsock2.h>
-#include <Ws2tcpip.h>
-#include <sys/stat.h>
-#define stat _stat
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <ctype.h>
-#include <errno.h>
-#include <sys/types.h>
-#include "ppr/net/Socket.hpp"
-
-using namespace apache::ppr::net;
-
-inline int
-SOCKETclose( Socket::SocketHandle sock )
-{
-#ifdef unix
- return ::close(sock);
-#else
- return ::closesocket(sock);
-#endif
-}
-
-#ifndef unix // Static socket initializer needed for winsock
-Socket::StaticSocketInitializer::StaticSocketInitializer () {
- const WORD version_needed = MAKEWORD(2,2); // lo-order byte: major version
- WSAData temp;
- if (WSAStartup(version_needed, &temp)){
- socketInitError = new SocketException ("winsock.dll was not found");
- }
-}
-Socket::StaticSocketInitializer::~StaticSocketInitializer () {
- WSACleanup();
-}
-
-Socket::StaticSocketInitializer apache::ppr::net::Socket::staticSocketInitializer;
-#endif
-
-Socket::Socket() : socketHandle (INVALID_SOCKET_HANDLE)
-{
-#ifndef unix
- if (staticSocketInitializer.getSocketInitError() != NULL) {
- throw *staticSocketInitializer.getSocketInitError();
- }
-#endif
-}
-
-Socket::Socket(Socket::SocketHandle socketHandle) : socketHandle (socketHandle)
-{
-}
-
-Socket::~Socket()
-{
- if (isConnected()) {
- // No shutdown, just close - dont want blocking destructor.
- SOCKETclose (socketHandle);
- }
-}
-
-void
-Socket::connect (const char* host, int port) throw (SocketException)
-{
- int ret;
- SocketHandle cs_socket_handle;
- if (isConnected()) {
- throw SocketException ("Socket already connected");
- }
- cs_socket_handle = ::socket(AF_INET, SOCK_STREAM, 0);
- if (cs_socket_handle < 0) {
- throw SocketException ("Could not create socket");
- }
- if (port <= 0 || port > 65535) {
- throw SocketException ("Port out of range");
- }
- sockaddr_in target_addr;
- target_addr.sin_family = AF_INET;
- target_addr.sin_port = htons((short)port);
- target_addr.sin_addr.s_addr = 0; // To be set later down...
- memset(&target_addr.sin_zero, 0, sizeof(target_addr.sin_zero));
-
- // Resolve name
- ::addrinfo hints;
- memset(&hints, 0, sizeof(addrinfo));
- hints.ai_family = PF_INET;
- struct addrinfo *res_ptr = NULL;
- if (::getaddrinfo(host, NULL, &hints, &res_ptr) != 0 || res_ptr == NULL) {
- throw SocketException ("Could not resolve name");
- } else {
- assert(res_ptr->ai_addr->sa_family == AF_INET);
- // Porting: On both 32bit and 64 bit systems that we compile to soo far, sin_addr is a 32 bit value, not an unsigned long.
- assert(sizeof(((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr) == 4);
- target_addr.sin_addr.s_addr = ((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr;
- freeaddrinfo(res_ptr);
- }
-
- ret = ::connect(cs_socket_handle, (const sockaddr *) &target_addr, sizeof(target_addr));
- if (ret < 0) {
- SOCKETclose (cs_socket_handle);
- throw SocketException ("Could not connect to host");
- }
- socketHandle = cs_socket_handle;
-}
-
-void
-Socket::setSoTimeout (int millisecs) throw (SocketException)
-{
-#ifdef unix
- timeval timot;
- timot.tv_sec = millisecs / 1000;
- timot.tv_usec = (millisecs % 1000) * 1000;
-#else
- int timot = millisecs;
-#endif
- ::setsockopt (socketHandle, SOL_SOCKET, SO_RCVTIMEO, (const char*) &timot, sizeof (timot));
- ::setsockopt (socketHandle, SOL_SOCKET, SO_SNDTIMEO, (const char*) &timot, sizeof (timot));
-}
-
-int
-Socket::getSoTimeout () const
-{
-#ifdef unix
- timeval timot;
- timot.tv_sec = 0;
- timot.tv_usec = 0;
- socklen_t size = sizeof(timot);
-#else
- int timot = 0;
- int size = sizeof(timot);
-#endif
-
- ::getsockopt (socketHandle, SOL_SOCKET, SO_RCVTIMEO, (char*) &timot, &size);
-#ifdef unix
- return (timot.tv_sec * 1000) + (timot.tv_usec / 1000);
-#else
- return timot;
-#endif
-}
-#include "ppr/util/Hex.hpp"
-
-int Socket::receive (char* buff, int size) throw (SocketException)
-{
- if (!isConnected()) {
- throw SocketException ("Socket not connected");
- }
-#ifdef unix
- int rc = ::read(this->socketHandle, buff, size);
- if (rc < 0) {
- throw SocketException ("Socket::receieve() failed - socket may have been disconnected") ;
- }
-#else
- int rc = ::recv(this->socketHandle, buff, size, 0);
- if (rc < 0) {
- char errmsg[256];
- sprintf (errmsg, "Socket::receive() failed. WSAGetLastError() returned %d", WSAGetLastError());
- throw SocketException (errmsg);
- }
- //printf ("----receive---[%s]\n", apache::ppr::util::Hex::toString (array<char> (buff, rc))->c_str());
-#endif
- return rc;
-}
-
-int
-Socket::send (const char* buff, int size) throw (SocketException)
-{
- if (!isConnected()) {
- throw SocketException ("Socket not connected");
- }
-#ifdef unix
- int rc = ::write(this->socketHandle, buff, size);
- if (rc < 0) {
- throw SocketException ("Socket::send() failed - socket may have been disconnected");
- }
-#else
- int rc = ::send(this->socketHandle, buff, size, 0);
- if (rc < 0) {
- char errmsg[256];
- sprintf (errmsg, "Socket::send() failed. WSAGetLastError() returned %d", WSAGetLastError());
- throw SocketException (errmsg);
- }
-#endif
- //printf ("SOCKETSEND[%s]\n", Hex::toString (array<char> (buff, rc))->c_str());
- return rc;
-}
-
-int
-Socket::send (const unsigned char* buff, int size) throw (SocketException)
-{
- return send (reinterpret_cast<const char*> (buff), size);
-}
-
-
-void
-Socket::close ()
-{
- if (isConnected()) {
- ::shutdown(this->socketHandle, 2);
- SOCKETclose (this->socketHandle);
- this->socketHandle = INVALID_SOCKET_HANDLE;
- }
-}
-
-bool
-Socket::isConnected() const {
- return this->socketHandle != INVALID_SOCKET_HANDLE;
-}
-
-
-//
-// Unit test
-//
-#ifdef UNITTEST
-
-#include "ppr/util/ifr/array"
-#include <iostream>
-#include <cassert>
-#include "Thread.hpp"
-#include "ServerSocket.hpp"
-
-class TestServer : public Thread
-{
-public:
- TestServer () {}
-protected:
- virtual void run () throw (p<exception>)
- {
- p<ServerSocket> serverSocket = new ServerSocket();
- serverSocket->bind ("127.0.0.1", 19000);
- cout << "Server bind successful" << endl;
- p<ISocket> client = serverSocket->accept();
- cout << "Server has accepted a connection" << endl;
- array<char> buff (13);
- int count = client->receive (buff.c_array(), (int)buff.size());
- cout << "Server has received " << count << " bytes from client" << endl;
- assert (count == 13);
- assert (strcmp (buff.c_array(), "Hello Socket") == 0);
- cout << "Message was as expected" << endl;
- cout << "Server sending Good Bye to client and closing connection" << endl;
- client->send ("Good Bye", 9);
- client->close();
- }
-};
-
-void testSocket()
-{
- p<TestServer> server = new TestServer();
- cout << "Starting up test server" << endl;
- server->start ();
- Socket s;
- cout << "Trying to connect to server" << endl;
- s.connect ("127.0.0.1", 19000);
- cout << "Client sending message to server" << endl;
- s.send ("Hello Socket", 13);
- cout << "Client has sent message now" << endl;
- array<char> buff (9);
- int count = s.receive (buff.c_array(), (int) buff.size());
- cout << "Client got a response from server of " << count << " bytes." << endl;
- assert (count == 9);
- assert (strcmp (buff.c_array(), "Good Bye") == 0);
- cout << "Client has verified the server's message" << endl;
- cout << "Client closes the connection" << endl;
- s.close();
-}
-
-#endif // UNITTEST
-
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifdef unix
+#include <unistd.h>
+#include <netdb.h>
+#include <fcntl.h>
+#include <sys/file.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#else
+#include <Winsock2.h>
+#include <Ws2tcpip.h>
+#include <sys/stat.h>
+#define stat _stat
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <errno.h>
+#include <sys/types.h>
+#include "ppr/net/Socket.hpp"
+
+using namespace apache::ppr::net;
+
+inline int
+SOCKETclose( Socket::SocketHandle sock )
+{
+#ifdef unix
+ return ::close(sock);
+#else
+ return ::closesocket(sock);
+#endif
+}
+
+#ifndef unix // Static socket initializer needed for winsock
+Socket::StaticSocketInitializer::StaticSocketInitializer () {
+ const WORD version_needed = MAKEWORD(2,2); // lo-order byte: major version
+ WSAData temp;
+ if (WSAStartup(version_needed, &temp)){
+ socketInitError = new SocketException ("winsock.dll was not found");
+ }
+}
+Socket::StaticSocketInitializer::~StaticSocketInitializer () {
+ WSACleanup();
+}
+
+Socket::StaticSocketInitializer apache::ppr::net::Socket::staticSocketInitializer;
+#endif
+
+Socket::Socket() : socketHandle (INVALID_SOCKET_HANDLE)
+{
+#ifndef unix
+ if (staticSocketInitializer.getSocketInitError() != NULL) {
+ throw *staticSocketInitializer.getSocketInitError();
+ }
+#endif
+}
+
+Socket::Socket(Socket::SocketHandle socketHandle) : socketHandle (socketHandle)
+{
+}
+
+Socket::~Socket()
+{
+ if (isConnected()) {
+ // No shutdown, just close - dont want blocking destructor.
+ SOCKETclose (socketHandle);
+ }
+}
+
+void
+Socket::connect (const char* host, int port) throw (SocketException)
+{
+ int ret;
+ SocketHandle cs_socket_handle;
+ if (isConnected()) {
+ throw SocketException ("Socket already connected");
+ }
+ cs_socket_handle = ::socket(AF_INET, SOCK_STREAM, 0);
+ if (cs_socket_handle < 0) {
+ throw SocketException ("Could not create socket");
+ }
+ if (port <= 0 || port > 65535) {
+ throw SocketException ("Port out of range");
+ }
+ sockaddr_in target_addr;
+ target_addr.sin_family = AF_INET;
+ target_addr.sin_port = htons((short)port);
+ target_addr.sin_addr.s_addr = 0; // To be set later down...
+ memset(&target_addr.sin_zero, 0, sizeof(target_addr.sin_zero));
+
+ // Resolve name
+ ::addrinfo hints;
+ memset(&hints, 0, sizeof(addrinfo));
+ hints.ai_family = PF_INET;
+ struct addrinfo *res_ptr = NULL;
+ if (::getaddrinfo(host, NULL, &hints, &res_ptr) != 0 || res_ptr == NULL) {
+ throw SocketException ("Could not resolve name");
+ } else {
+ assert(res_ptr->ai_addr->sa_family == AF_INET);
+ // Porting: On both 32bit and 64 bit systems that we compile to soo far, sin_addr is a 32 bit value, not an unsigned long.
+ assert(sizeof(((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr) == 4);
+ target_addr.sin_addr.s_addr = ((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr;
+ freeaddrinfo(res_ptr);
+ }
+
+ ret = ::connect(cs_socket_handle, (const sockaddr *) &target_addr, sizeof(target_addr));
+ if (ret < 0) {
+ SOCKETclose (cs_socket_handle);
+ throw SocketException ("Could not connect to host");
+ }
+ socketHandle = cs_socket_handle;
+}
+
+void
+Socket::setSoTimeout (int millisecs) throw (SocketException)
+{
+#ifdef unix
+ timeval timot;
+ timot.tv_sec = millisecs / 1000;
+ timot.tv_usec = (millisecs % 1000) * 1000;
+#else
+ int timot = millisecs;
+#endif
+ ::setsockopt (socketHandle, SOL_SOCKET, SO_RCVTIMEO, (const char*) &timot, sizeof (timot));
+ ::setsockopt (socketHandle, SOL_SOCKET, SO_SNDTIMEO, (const char*) &timot, sizeof (timot));
+}
+
+int
+Socket::getSoTimeout () const
+{
+#ifdef unix
+ timeval timot;
+ timot.tv_sec = 0;
+ timot.tv_usec = 0;
+ socklen_t size = sizeof(timot);
+#else
+ int timot = 0;
+ int size = sizeof(timot);
+#endif
+
+ ::getsockopt (socketHandle, SOL_SOCKET, SO_RCVTIMEO, (char*) &timot, &size);
+#ifdef unix
+ return (timot.tv_sec * 1000) + (timot.tv_usec / 1000);
+#else
+ return timot;
+#endif
+}
+#include "ppr/util/Hex.hpp"
+
+int Socket::receive (char* buff, int size) throw (SocketException)
+{
+ if (!isConnected()) {
+ throw SocketException ("Socket not connected");
+ }
+#ifdef unix
+ int rc = ::read(this->socketHandle, buff, size);
+ if (rc < 0) {
+ throw SocketException ("Socket::receieve() failed - socket may have been disconnected") ;
+ }
+#else
+ int rc = ::recv(this->socketHandle, buff, size, 0);
+ if (rc < 0) {
+ char errmsg[256];
+ sprintf (errmsg, "Socket::receive() failed. WSAGetLastError() returned %d", WSAGetLastError());
+ throw SocketException (errmsg);
+ }
+ //printf ("----receive---[%s]\n", apache::ppr::util::Hex::toString (array<char> (buff, rc))->c_str());
+#endif
+ return rc;
+}
+
+int
+Socket::send (const char* buff, int size) throw (SocketException)
+{
+ if (!isConnected()) {
+ throw SocketException ("Socket not connected");
+ }
+#ifdef unix
+ int rc = ::write(this->socketHandle, buff, size);
+ if (rc < 0) {
+ throw SocketException ("Socket::send() failed - socket may have been disconnected");
+ }
+#else
+ int rc = ::send(this->socketHandle, buff, size, 0);
+ if (rc < 0) {
+ char errmsg[256];
+ sprintf (errmsg, "Socket::send() failed. WSAGetLastError() returned %d", WSAGetLastError());
+ throw SocketException (errmsg);
+ }
+#endif
+ //printf ("SOCKETSEND[%s]\n", Hex::toString (array<char> (buff, rc))->c_str());
+ return rc;
+}
+
+int
+Socket::send (const unsigned char* buff, int size) throw (SocketException)
+{
+ return send (reinterpret_cast<const char*> (buff), size);
+}
+
+
+void
+Socket::close ()
+{
+ if (isConnected()) {
+ ::shutdown(this->socketHandle, 2);
+ SOCKETclose (this->socketHandle);
+ this->socketHandle = INVALID_SOCKET_HANDLE;
+ }
+}
+
+bool
+Socket::isConnected() const {
+ return this->socketHandle != INVALID_SOCKET_HANDLE;
+}
+
+
+//
+// Unit test
+//
+#ifdef UNITTEST
+
+#include "ppr/util/ifr/array"
+#include <iostream>
+#include <cassert>
+#include "Thread.hpp"
+#include "ServerSocket.hpp"
+
+class TestServer : public Thread
+{
+public:
+ TestServer () {}
+protected:
+ virtual void run () throw (p<exception>)
+ {
+ p<ServerSocket> serverSocket = new ServerSocket();
+ serverSocket->bind ("127.0.0.1", 19000);
+ cout << "Server bind successful" << endl;
+ p<ISocket> client = serverSocket->accept();
+ cout << "Server has accepted a connection" << endl;
+ array<char> buff (13);
+ int count = client->receive (buff.c_array(), (int)buff.size());
+ cout << "Server has received " << count << " bytes from client" << endl;
+ assert (count == 13);
+ assert (strcmp (buff.c_array(), "Hello Socket") == 0);
+ cout << "Message was as expected" << endl;
+ cout << "Server sending Good Bye to client and closing connection" << endl;
+ client->send ("Good Bye", 9);
+ client->close();
+ }
+};
+
+void testSocket()
+{
+ p<TestServer> server = new TestServer();
+ cout << "Starting up test server" << endl;
+ server->start ();
+ Socket s;
+ cout << "Trying to connect to server" << endl;
+ s.connect ("127.0.0.1", 19000);
+ cout << "Client sending message to server" << endl;
+ s.send ("Hello Socket", 13);
+ cout << "Client has sent message now" << endl;
+ array<char> buff (9);
+ int count = s.receive (buff.c_array(), (int) buff.size());
+ cout << "Client got a response from server of " << count << " bytes." << endl;
+ assert (count == 9);
+ assert (strcmp (buff.c_array(), "Good Bye") == 0);
+ cout << "Client has verified the server's message" << endl;
+ cout << "Client closes the connection" << endl;
+ s.close();
+}
+
+#endif // UNITTEST
+
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Socket.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Socket.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Socket.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Socket.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Socket.hpp Fri Jul 28 01:22:48 2006
@@ -1,115 +1,115 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_Socket_hpp_
-#define Ppr_Socket_hpp_
-
-#include "ISocket.hpp"
-#ifndef unix
-#include <Winsock2.h> // SOCKET
-#endif
-
-namespace apache
-{
- namespace ppr
- {
- namespace net
- {
- using namespace ifr;
-
-/*
- *
- */
-class Socket : public ISocket
-{
-public:
-#ifdef unix
- typedef int SocketHandle;
-#else
- typedef SOCKET SocketHandle;
-#endif
- static const SocketHandle INVALID_SOCKET_HANDLE = (SocketHandle) -1;
-private:
- SocketHandle socketHandle;
-public:
- /** Construct a non-connected socket.
- */
- Socket ();
- /** Construct a connected or bound socket based on given
- socket handle.
- */
- Socket (SocketHandle socketHandle);
- /** Destruct.
- Releases the socket handle but not
- gracefully shut down the connection.
- */
- virtual ~Socket();
-public:
- /**
- */
- virtual void connect (const char* host, int port) throw (SocketException);
- /**
- */
- virtual void setSoTimeout (int millisec) throw (SocketException);
- /**
- */
- virtual int getSoTimeout () const;
- /**
- */
- virtual int receive (char* buff, int size) throw (SocketException);
- /**
- */
- virtual int send (const unsigned char* buff, int size) throw (SocketException);
- /**
- */
- virtual int send (const char* buff, int size) throw (SocketException);
- /**
- */
- virtual void close ();
- /**
- */
- virtual bool isConnected() const;
-protected:
- SocketHandle getSocketHandle () {
- return socketHandle;
- }
- void setSocketHandle (SocketHandle socketHandle) {
- this->socketHandle = socketHandle;
- }
-public:
-#ifndef unix
- // WINDOWS needs initialization of winsock
- class StaticSocketInitializer {
- private:
- p<SocketException> socketInitError;
- public:
- p<SocketException> getSocketInitError () {
- return socketInitError;
- }
- StaticSocketInitializer ();
- virtual ~StaticSocketInitializer ();
- };
- static StaticSocketInitializer staticSocketInitializer;
-#endif
-
-};
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_Socket_hpp_*/
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_Socket_hpp_
+#define Ppr_Socket_hpp_
+
+#include "ISocket.hpp"
+#ifndef unix
+#include <Winsock2.h> // SOCKET
+#endif
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace net
+ {
+ using namespace ifr;
+
+/*
+ *
+ */
+class Socket : public ISocket
+{
+public:
+#ifdef unix
+ typedef int SocketHandle;
+#else
+ typedef SOCKET SocketHandle;
+#endif
+ static const SocketHandle INVALID_SOCKET_HANDLE = (SocketHandle) -1;
+private:
+ SocketHandle socketHandle;
+public:
+ /** Construct a non-connected socket.
+ */
+ Socket ();
+ /** Construct a connected or bound socket based on given
+ socket handle.
+ */
+ Socket (SocketHandle socketHandle);
+ /** Destruct.
+ Releases the socket handle but not
+ gracefully shut down the connection.
+ */
+ virtual ~Socket();
+public:
+ /**
+ */
+ virtual void connect (const char* host, int port) throw (SocketException);
+ /**
+ */
+ virtual void setSoTimeout (int millisec) throw (SocketException);
+ /**
+ */
+ virtual int getSoTimeout () const;
+ /**
+ */
+ virtual int receive (char* buff, int size) throw (SocketException);
+ /**
+ */
+ virtual int send (const unsigned char* buff, int size) throw (SocketException);
+ /**
+ */
+ virtual int send (const char* buff, int size) throw (SocketException);
+ /**
+ */
+ virtual void close ();
+ /**
+ */
+ virtual bool isConnected() const;
+protected:
+ SocketHandle getSocketHandle () {
+ return socketHandle;
+ }
+ void setSocketHandle (SocketHandle socketHandle) {
+ this->socketHandle = socketHandle;
+ }
+public:
+#ifndef unix
+ // WINDOWS needs initialization of winsock
+ class StaticSocketInitializer {
+ private:
+ p<SocketException> socketInitError;
+ public:
+ p<SocketException> getSocketInitError () {
+ return socketInitError;
+ }
+ StaticSocketInitializer ();
+ virtual ~StaticSocketInitializer ();
+ };
+ static StaticSocketInitializer staticSocketInitializer;
+#endif
+
+};
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_Socket_hpp_*/
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Socket.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/SocketException.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/SocketException.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/SocketException.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/SocketException.hpp Fri Jul 28 01:22:48 2006
@@ -1,51 +1,51 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_SocketException_hpp_
-#define Ppr_SocketException_hpp_
-
-#include <stdexcept>
-
-namespace apache
-{
- namespace ppr
- {
- namespace net
- {
- using namespace std;
-
-/**
- */
-class SocketException : public exception
-{
-protected:
- string msg;
-public:
- SocketException(const char* message) : msg (message) {};
- virtual ~SocketException() throw() {}
- virtual const char* what() const throw () {
- return msg.c_str();
- }
-} ;
-
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_SocketException_hpp_*/
-
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_SocketException_hpp_
+#define Ppr_SocketException_hpp_
+
+#include <stdexcept>
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace net
+ {
+ using namespace std;
+
+/**
+ */
+class SocketException : public exception
+{
+protected:
+ string msg;
+public:
+ SocketException(const char* message) : msg (message) {};
+ virtual ~SocketException() throw() {}
+ virtual const char* what() const throw () {
+ return msg.c_str();
+ }
+} ;
+
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_SocketException_hpp_*/
+
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/SocketException.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/SocketFactory.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/SocketFactory.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/SocketFactory.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/SocketFactory.hpp Fri Jul 28 01:22:48 2006
@@ -1,50 +1,50 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_SocketFactory_hpp_
-#define Ppr_SocketFactory_hpp_
-
-#include "ppr/net/ISocketFactory.hpp"
-#include "ppr/net/Socket.hpp"
-
-namespace apache
-{
- namespace ppr
- {
- namespace net
- {
- using namespace std;
-
-/*
- *
- */
-class SocketFactory : public ISocketFactory
-{
-public:
- /** Creates an unconnected TCP/IP socket ready to call connect() on.
- */
- virtual p<ISocket> createSocket() {
- return new Socket();
- }
-};
-
-/* namespave */
- }
- }
-}
-
-#endif /*Ppr_SocketFactory_hpp_*/
-
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_SocketFactory_hpp_
+#define Ppr_SocketFactory_hpp_
+
+#include "ppr/net/ISocketFactory.hpp"
+#include "ppr/net/Socket.hpp"
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace net
+ {
+ using namespace std;
+
+/*
+ *
+ */
+class SocketFactory : public ISocketFactory
+{
+public:
+ /** Creates an unconnected TCP/IP socket ready to call connect() on.
+ */
+ virtual p<ISocket> createSocket() {
+ return new Socket();
+ }
+};
+
+/* namespave */
+ }
+ }
+}
+
+#endif /*Ppr_SocketFactory_hpp_*/
+
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/SocketFactory.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Uri.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Uri.cpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Uri.cpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Uri.cpp Fri Jul 28 01:22:48 2006
@@ -1,226 +1,226 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "ppr/net/Uri.hpp"
-
-using namespace apache::ppr::net;
-
-#ifdef unix
-#define _stricmp strcasecmp
-#endif
-
-Uri::Uri (const string& absoluteUri) : port_(0), bits_ (IS_FAIL)
-{
- if (absoluteUri.empty()) {
- bits_ = IS_EMPTY;
- return;
- }
- //
- // scheme
- //
- size_t pColonSlashSlash = absoluteUri.find ("://");
- if (pColonSlashSlash == absoluteUri.npos) return; // must contain "://"
- scheme_ = absoluteUri.substr (0, pColonSlashSlash);
- size_t pHost = pColonSlashSlash + 3; // strlen ("://")
-
- //
- // host, port, authority_
- //
- size_t pColonOrSlash = absoluteUri.find_first_of (":/", pHost);
- if (pColonOrSlash != absoluteUri.npos && absoluteUri[pColonOrSlash] == ':') {
- host_ = absoluteUri.substr (pHost, pColonOrSlash - pHost);
- long port = atol(absoluteUri.substr (pColonOrSlash + 1).c_str());
- if (port < 0 || port > 65535) return; // If port is present, it must be between 0 and 65535.
- port_ = (unsigned short) port;
- pColonOrSlash = absoluteUri.find ('/', pColonOrSlash + 1); // Make pColonOrSlash point to slash.
- if (pColonOrSlash != absoluteUri.npos) {
- authority_ = absoluteUri.substr (pHost, pColonOrSlash - pHost);
- } else {
- authority_ = absoluteUri.substr (pHost);
- }
- } else {
- port_ = getDefaultPort (scheme_);
- if (pColonOrSlash == absoluteUri.npos) {
- host_ = absoluteUri.substr (pHost);
- } else {
- host_ = absoluteUri.substr (pHost, pColonOrSlash - pHost);
- }
- authority_ = host_;
- }
-
- //
- // path
- //
- if (pColonOrSlash == absoluteUri.npos) {
- path_ = "/";
- } else {
- size_t pQuery = absoluteUri.find ('?', pColonOrSlash);
- if (pQuery == absoluteUri.npos) {
- path_ = absoluteUri.substr (pColonOrSlash);
- } else {
- path_ = absoluteUri.substr (pColonOrSlash, pQuery - pColonOrSlash);
- //
- // query
- //
- query_ = absoluteUri.substr (pQuery + 1);
- }
- }
-
- // isFail
- if (!scheme_.empty() && !path_.empty()) {
- bits_ = 0;
- }
-}
-
-Uri::Uri (string uri, const Uri& baseUri) : port_(0), bits_ (IS_FAIL)
-{
- if (uri[0] == '/') {
- //
- // uri is absolute path
- //
- *this = baseUri;
- size_t pQuery = uri.find ('?');
- if (pQuery == uri.npos) {
- path_ = uri;
- query_.clear();
- } else {
- path_ = uri.substr (0, pQuery);
- query_ = uri.substr (pQuery + 1);
- }
- } else {
- size_t pColonOrSlash = uri.find_first_of ("/:");
- if (pColonOrSlash != uri.npos && uri[pColonOrSlash] == ':' && pColonOrSlash == uri.find ("://")) {
- //
- // uri is an Uri
- //
- *this = uri;
- } else {
- //
- // uri is a relative path
- //
-
- // Copy everything from base Uri to this instance.
- // We will change path and query only...
- *this = baseUri;
-
- // Resolve ".." and "." in beginning of uri:
- // Check for last slash in base Uri (where to insert uri)
- size_t pLastSlash = path_.rfind ('/');
- while (uri.length() > 0 && uri[0] == '.') {
- if (uri.length() == 1) {
- // uri is exactly "."
- uri.clear();
- break;
- } else if (uri[1] == '/') {
- // uri begins with "./"
- uri = uri.substr (2);
- } else if (uri[1] == '.') {
- //
- // Uri begins with ".." but we dont know the next character...
- //
- if (uri.length() == 2) {
- // uri is exactly ".."
- uri.clear();
- // Navigate upwards in directory tree (of path_)
- if (pLastSlash != path_.npos && pLastSlash > 0) {
- assert (string ("/1/2/").rfind ('/') == 4); // just to make sure how rfind() works...
- assert (string ("/1/2/").rfind ('/', 4) == 4); // --""--
- assert (string ("/1/2/").rfind ('/', 3) == 2); // --""--
- assert (string ("/").rfind ('/', 0) == 0); // --""--
- pLastSlash = path_.rfind ('/', pLastSlash - 1);
- }
- break;
- } else if (uri[2] == '/') {
- // uri begins with "../"
- uri = uri.substr (3);
- // Navigate upwards in directory tree (of path_)
- if (pLastSlash != path_.npos && pLastSlash > 0) {
- assert (string ("/1/2/").rfind ('/') == 4); // just to make sure how rfind() works...
- assert (string ("/1/2/").rfind ('/', 4) == 4); // --""--
- assert (string ("/1/2/").rfind ('/', 3) == 2); // --""--
- assert (string ("/").rfind ('/', 0) == 0); // --""--
- pLastSlash = path_.rfind ('/', pLastSlash - 1);
- }
- }
- }
- }
-
- // Check for query in given uri (in order to split path from query, as we do in this class)
- size_t pQuery = uri.find ('?');
-
- if (pQuery == uri.npos) {
- // No query in the uri
- if (pLastSlash != path_.npos) {
- // Append URI after last slash in base Uri's path
- path_ = path_.substr (0, pLastSlash + 1) + uri;
- } else {
- // No slash found in base Uri's path. Append a slash in beginning.
- path_ = "/" + uri;
- }
- // Clear the query
- query_.clear();
- } else {
- // Query in the uri
- if (pLastSlash != path_.npos) {
- // Append URI after last slash in base Uri's path
- path_ = path_.substr (0, pLastSlash + 1) + uri.substr (0, pQuery);
- } else {
- // No slash found in base Uri's path. Append a slash in beginning.
- path_ = "/" + uri.substr (0, pQuery);
- }
- // Get the query from uri.
- query_ = uri.substr (pQuery + 1);
- }
-
- }
- }
-}
-
-unsigned short Uri::getDefaultPort (const string& scheme)
-{
- if (_stricmp (scheme.c_str(), "http") == 0) {
- return 80;
- } else if (_stricmp (scheme.c_str(), "https") == 0) {
- return 443;
- } else if (_stricmp (scheme.c_str(), "ftp") == 0) {
- return 21;
- } else if (_stricmp (scheme.c_str(), "ssh") == 0) {
- return 22;
- } else if (_stricmp (scheme.c_str(), "telnet") == 0) {
- return 23;
- } else if (_stricmp (scheme.c_str(), "smtp") == 0) {
- return 25;
- } else if (_stricmp (scheme.c_str(), "pop3") == 0) {
- return 110;
- } else if (_stricmp (scheme.c_str(), "radius") == 0) {
- return 1812;
- } else {
- return 0;
- }
-}
-
-bool Uri::isSecure() const
-{
- if (_stricmp (scheme_.c_str(), "https") == 0 ||
- _stricmp (scheme_.c_str(), "ssh") == 0 ||
- _stricmp (scheme_.c_str(), "ftps") == 0)
- {
- return true;
- } else {
- return false;
- }
-}
-
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "ppr/net/Uri.hpp"
+
+using namespace apache::ppr::net;
+
+#ifdef unix
+#define _stricmp strcasecmp
+#endif
+
+Uri::Uri (const string& absoluteUri) : port_(0), bits_ (IS_FAIL)
+{
+ if (absoluteUri.empty()) {
+ bits_ = IS_EMPTY;
+ return;
+ }
+ //
+ // scheme
+ //
+ size_t pColonSlashSlash = absoluteUri.find ("://");
+ if (pColonSlashSlash == absoluteUri.npos) return; // must contain "://"
+ scheme_ = absoluteUri.substr (0, pColonSlashSlash);
+ size_t pHost = pColonSlashSlash + 3; // strlen ("://")
+
+ //
+ // host, port, authority_
+ //
+ size_t pColonOrSlash = absoluteUri.find_first_of (":/", pHost);
+ if (pColonOrSlash != absoluteUri.npos && absoluteUri[pColonOrSlash] == ':') {
+ host_ = absoluteUri.substr (pHost, pColonOrSlash - pHost);
+ long port = atol(absoluteUri.substr (pColonOrSlash + 1).c_str());
+ if (port < 0 || port > 65535) return; // If port is present, it must be between 0 and 65535.
+ port_ = (unsigned short) port;
+ pColonOrSlash = absoluteUri.find ('/', pColonOrSlash + 1); // Make pColonOrSlash point to slash.
+ if (pColonOrSlash != absoluteUri.npos) {
+ authority_ = absoluteUri.substr (pHost, pColonOrSlash - pHost);
+ } else {
+ authority_ = absoluteUri.substr (pHost);
+ }
+ } else {
+ port_ = getDefaultPort (scheme_);
+ if (pColonOrSlash == absoluteUri.npos) {
+ host_ = absoluteUri.substr (pHost);
+ } else {
+ host_ = absoluteUri.substr (pHost, pColonOrSlash - pHost);
+ }
+ authority_ = host_;
+ }
+
+ //
+ // path
+ //
+ if (pColonOrSlash == absoluteUri.npos) {
+ path_ = "/";
+ } else {
+ size_t pQuery = absoluteUri.find ('?', pColonOrSlash);
+ if (pQuery == absoluteUri.npos) {
+ path_ = absoluteUri.substr (pColonOrSlash);
+ } else {
+ path_ = absoluteUri.substr (pColonOrSlash, pQuery - pColonOrSlash);
+ //
+ // query
+ //
+ query_ = absoluteUri.substr (pQuery + 1);
+ }
+ }
+
+ // isFail
+ if (!scheme_.empty() && !path_.empty()) {
+ bits_ = 0;
+ }
+}
+
+Uri::Uri (string uri, const Uri& baseUri) : port_(0), bits_ (IS_FAIL)
+{
+ if (uri[0] == '/') {
+ //
+ // uri is absolute path
+ //
+ *this = baseUri;
+ size_t pQuery = uri.find ('?');
+ if (pQuery == uri.npos) {
+ path_ = uri;
+ query_.clear();
+ } else {
+ path_ = uri.substr (0, pQuery);
+ query_ = uri.substr (pQuery + 1);
+ }
+ } else {
+ size_t pColonOrSlash = uri.find_first_of ("/:");
+ if (pColonOrSlash != uri.npos && uri[pColonOrSlash] == ':' && pColonOrSlash == uri.find ("://")) {
+ //
+ // uri is an Uri
+ //
+ *this = uri;
+ } else {
+ //
+ // uri is a relative path
+ //
+
+ // Copy everything from base Uri to this instance.
+ // We will change path and query only...
+ *this = baseUri;
+
+ // Resolve ".." and "." in beginning of uri:
+ // Check for last slash in base Uri (where to insert uri)
+ size_t pLastSlash = path_.rfind ('/');
+ while (uri.length() > 0 && uri[0] == '.') {
+ if (uri.length() == 1) {
+ // uri is exactly "."
+ uri.clear();
+ break;
+ } else if (uri[1] == '/') {
+ // uri begins with "./"
+ uri = uri.substr (2);
+ } else if (uri[1] == '.') {
+ //
+ // Uri begins with ".." but we dont know the next character...
+ //
+ if (uri.length() == 2) {
+ // uri is exactly ".."
+ uri.clear();
+ // Navigate upwards in directory tree (of path_)
+ if (pLastSlash != path_.npos && pLastSlash > 0) {
+ assert (string ("/1/2/").rfind ('/') == 4); // just to make sure how rfind() works...
+ assert (string ("/1/2/").rfind ('/', 4) == 4); // --""--
+ assert (string ("/1/2/").rfind ('/', 3) == 2); // --""--
+ assert (string ("/").rfind ('/', 0) == 0); // --""--
+ pLastSlash = path_.rfind ('/', pLastSlash - 1);
+ }
+ break;
+ } else if (uri[2] == '/') {
+ // uri begins with "../"
+ uri = uri.substr (3);
+ // Navigate upwards in directory tree (of path_)
+ if (pLastSlash != path_.npos && pLastSlash > 0) {
+ assert (string ("/1/2/").rfind ('/') == 4); // just to make sure how rfind() works...
+ assert (string ("/1/2/").rfind ('/', 4) == 4); // --""--
+ assert (string ("/1/2/").rfind ('/', 3) == 2); // --""--
+ assert (string ("/").rfind ('/', 0) == 0); // --""--
+ pLastSlash = path_.rfind ('/', pLastSlash - 1);
+ }
+ }
+ }
+ }
+
+ // Check for query in given uri (in order to split path from query, as we do in this class)
+ size_t pQuery = uri.find ('?');
+
+ if (pQuery == uri.npos) {
+ // No query in the uri
+ if (pLastSlash != path_.npos) {
+ // Append URI after last slash in base Uri's path
+ path_ = path_.substr (0, pLastSlash + 1) + uri;
+ } else {
+ // No slash found in base Uri's path. Append a slash in beginning.
+ path_ = "/" + uri;
+ }
+ // Clear the query
+ query_.clear();
+ } else {
+ // Query in the uri
+ if (pLastSlash != path_.npos) {
+ // Append URI after last slash in base Uri's path
+ path_ = path_.substr (0, pLastSlash + 1) + uri.substr (0, pQuery);
+ } else {
+ // No slash found in base Uri's path. Append a slash in beginning.
+ path_ = "/" + uri.substr (0, pQuery);
+ }
+ // Get the query from uri.
+ query_ = uri.substr (pQuery + 1);
+ }
+
+ }
+ }
+}
+
+unsigned short Uri::getDefaultPort (const string& scheme)
+{
+ if (_stricmp (scheme.c_str(), "http") == 0) {
+ return 80;
+ } else if (_stricmp (scheme.c_str(), "https") == 0) {
+ return 443;
+ } else if (_stricmp (scheme.c_str(), "ftp") == 0) {
+ return 21;
+ } else if (_stricmp (scheme.c_str(), "ssh") == 0) {
+ return 22;
+ } else if (_stricmp (scheme.c_str(), "telnet") == 0) {
+ return 23;
+ } else if (_stricmp (scheme.c_str(), "smtp") == 0) {
+ return 25;
+ } else if (_stricmp (scheme.c_str(), "pop3") == 0) {
+ return 110;
+ } else if (_stricmp (scheme.c_str(), "radius") == 0) {
+ return 1812;
+ } else {
+ return 0;
+ }
+}
+
+bool Uri::isSecure() const
+{
+ if (_stricmp (scheme_.c_str(), "https") == 0 ||
+ _stricmp (scheme_.c_str(), "ssh") == 0 ||
+ _stricmp (scheme_.c_str(), "ftps") == 0)
+ {
+ return true;
+ } else {
+ return false;
+ }
+}
+
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Uri.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Uri.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Uri.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Uri.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Uri.hpp Fri Jul 28 01:22:48 2006
@@ -1,150 +1,150 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_Uri_hpp_
-#define Ppr_Uri_hpp_
-
-#include <string>
-#include <assert.h>
-#include <stdlib.h>
-
-namespace apache
-{
- namespace ppr
- {
- namespace net
- {
- using namespace std;
-
-/*
- * Splits an Uri string into it's basic parts.
- * @author David Fahlander, PortWise
- */
-class Uri
-{
-public:
- // Constructs an empty URI.
- Uri() : port_(0), bits_ (IS_EMPTY) {};
-
- // Constructs an URI based on given absolute URI string.
- Uri(const string& absoluteUri);
-
- /** Construct an Uri based on an URI and a base Uri.
-
- Given URI can be a relative path, an absolute path or an entire Uri.
- If given URI is an absolute URI (begins with <scheme> "://", baseUri is ignored.
- If given URI begins with ".." or "." the constructed Uri will resolve the real
- path without "." or "..".
-
- @param uri URI relative to baseUri
- @baseUri The Uri of the document that referred to given URI.
- */
- Uri (string uri, const Uri& baseUri);
-public:
- /** Get scheme.
- */
- const string& scheme() const {return scheme_;}
- /** Get host.
- */
- const string& host() const {return host_;}
-
- /** Returns the port (if scheme supports port).
- If the port was omitted in the string that constructed the URI, the default
- port for that scheme is returned (if there is a default port for it). If no
- default port exists for the scheme and port was omitted in the string that
- constructed the URI, 0 is returned.
-
- For example, the URI
- http://127.0.0.1:8081/index.html has the port 8081 and the URI
- http://www.apache.org/index.html has the port 80 (default HTTP port).
-
- The default port-table is defined in Uri::getDefaultPort().
- */
- unsigned short port() const {return port_;}
-
- /** Returns the authority.
- The authority is equivalent to the host header when an HTTP URI is used. If a default
- port is used, the port part of the authority may be omitted. For example, the URI
- http://www.apache.org/index.html has the authority "www.apache.org" and the URI
- http://127.0.0.1:8081/index.html has the authority "127.0.0.1:8081".
- */
- const string& authority() const {return authority_;}
-
- /** Returns the path (without query).
- If no path, an empty string is returned.
- */
- const string& path() const {return path_;}
-
- /** Returns the query. If no query, an empty string is returned.
- */
- const string& query() const {return query_;}
-
- /** Returns true if URI has a query.
- */
- bool hasQuery () const {return !query_.empty();}
-
- /** Returns the path and query part of the URI.
- */
- string pathAndQuery() const {return (hasQuery() ? path() + "?" + query() : path());}
-
- /** Returns true if the URI failed to be interpreted in any of the constructors used.
- */
- bool isFail () const { return ((bits_ & IS_FAIL) != 0); }
-
- /** Returns true if the URI is empty.
- */
- bool isEmpty () const { return ((bits_ & IS_EMPTY) != 0); }
-
- /** Returns true if the URI is a URL using a secure scheme such as https.
- */
- bool isSecure() const;
-
- /** Converts this URI into a string.
- */
- string toString() const {
- if (isEmpty() || isFail()) {
- return "";
- } else if (hasQuery()) {
- return scheme() + "://" + authority() + path() + "?" + query();
- } else {
- return scheme() + "://" + authority() + path();
- }
- }
-public:
- /** Returns the default port if given scheme is a protocol that is recognized
- by this implementation.
- */
- static unsigned short getDefaultPort (const string& scheme);
-private:
- string scheme_;
- string host_;
- unsigned short port_;
- string authority_;
- string path_;
- string query_;
-private:
- static const unsigned char IS_EMPTY = 0x01;
- static const unsigned char IS_FAIL = 0x02;
- unsigned char bits_;
-};
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_Uri_hpp_*/
-
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_Uri_hpp_
+#define Ppr_Uri_hpp_
+
+#include <string>
+#include <assert.h>
+#include <stdlib.h>
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace net
+ {
+ using namespace std;
+
+/*
+ * Splits an Uri string into it's basic parts.
+ * @author David Fahlander, PortWise
+ */
+class Uri
+{
+public:
+ // Constructs an empty URI.
+ Uri() : port_(0), bits_ (IS_EMPTY) {};
+
+ // Constructs an URI based on given absolute URI string.
+ Uri(const string& absoluteUri);
+
+ /** Construct an Uri based on an URI and a base Uri.
+
+ Given URI can be a relative path, an absolute path or an entire Uri.
+ If given URI is an absolute URI (begins with <scheme> "://", baseUri is ignored.
+ If given URI begins with ".." or "." the constructed Uri will resolve the real
+ path without "." or "..".
+
+ @param uri URI relative to baseUri
+ @baseUri The Uri of the document that referred to given URI.
+ */
+ Uri (string uri, const Uri& baseUri);
+public:
+ /** Get scheme.
+ */
+ const string& scheme() const {return scheme_;}
+ /** Get host.
+ */
+ const string& host() const {return host_;}
+
+ /** Returns the port (if scheme supports port).
+ If the port was omitted in the string that constructed the URI, the default
+ port for that scheme is returned (if there is a default port for it). If no
+ default port exists for the scheme and port was omitted in the string that
+ constructed the URI, 0 is returned.
+
+ For example, the URI
+ http://127.0.0.1:8081/index.html has the port 8081 and the URI
+ http://www.apache.org/index.html has the port 80 (default HTTP port).
+
+ The default port-table is defined in Uri::getDefaultPort().
+ */
+ unsigned short port() const {return port_;}
+
+ /** Returns the authority.
+ The authority is equivalent to the host header when an HTTP URI is used. If a default
+ port is used, the port part of the authority may be omitted. For example, the URI
+ http://www.apache.org/index.html has the authority "www.apache.org" and the URI
+ http://127.0.0.1:8081/index.html has the authority "127.0.0.1:8081".
+ */
+ const string& authority() const {return authority_;}
+
+ /** Returns the path (without query).
+ If no path, an empty string is returned.
+ */
+ const string& path() const {return path_;}
+
+ /** Returns the query. If no query, an empty string is returned.
+ */
+ const string& query() const {return query_;}
+
+ /** Returns true if URI has a query.
+ */
+ bool hasQuery () const {return !query_.empty();}
+
+ /** Returns the path and query part of the URI.
+ */
+ string pathAndQuery() const {return (hasQuery() ? path() + "?" + query() : path());}
+
+ /** Returns true if the URI failed to be interpreted in any of the constructors used.
+ */
+ bool isFail () const { return ((bits_ & IS_FAIL) != 0); }
+
+ /** Returns true if the URI is empty.
+ */
+ bool isEmpty () const { return ((bits_ & IS_EMPTY) != 0); }
+
+ /** Returns true if the URI is a URL using a secure scheme such as https.
+ */
+ bool isSecure() const;
+
+ /** Converts this URI into a string.
+ */
+ string toString() const {
+ if (isEmpty() || isFail()) {
+ return "";
+ } else if (hasQuery()) {
+ return scheme() + "://" + authority() + path() + "?" + query();
+ } else {
+ return scheme() + "://" + authority() + path();
+ }
+ }
+public:
+ /** Returns the default port if given scheme is a protocol that is recognized
+ by this implementation.
+ */
+ static unsigned short getDefaultPort (const string& scheme);
+private:
+ string scheme_;
+ string host_;
+ unsigned short port_;
+ string authority_;
+ string path_;
+ string query_;
+private:
+ static const unsigned char IS_EMPTY = 0x01;
+ static const unsigned char IS_FAIL = 0x02;
+ unsigned char bits_;
+};
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_Uri_hpp_*/
+
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/net/Uri.hpp
------------------------------------------------------------------------------
svn:eol-style = native