You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(35) |
Dec
(2) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(37) |
Feb
(10) |
Mar
|
Apr
(2) |
May
(17) |
Jun
(1) |
Jul
(14) |
Aug
(14) |
Sep
(4) |
Oct
|
Nov
(14) |
Dec
(4) |
2005 |
Jan
(6) |
Feb
|
Mar
|
Apr
(6) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
(92) |
Dec
(12) |
2006 |
Jan
(3) |
Feb
(4) |
Mar
|
Apr
(5) |
May
(3) |
Jun
(15) |
Jul
(3) |
Aug
(1) |
Sep
(29) |
Oct
(1) |
Nov
(6) |
Dec
(5) |
2007 |
Jan
(2) |
Feb
(2) |
Mar
|
Apr
(3) |
May
(14) |
Jun
(2) |
Jul
(16) |
Aug
(73) |
Sep
(12) |
Oct
(9) |
Nov
(27) |
Dec
(3) |
2008 |
Jan
(4) |
Feb
(4) |
Mar
(3) |
Apr
(8) |
May
(23) |
Jun
(4) |
Jul
(1) |
Aug
(3) |
Sep
(7) |
Oct
(5) |
Nov
(1) |
Dec
(1) |
2009 |
Jan
|
Feb
(10) |
Mar
|
Apr
(4) |
May
(4) |
Jun
(10) |
Jul
|
Aug
(1) |
Sep
|
Oct
(7) |
Nov
|
Dec
(1) |
2010 |
Jan
|
Feb
(1) |
Mar
|
Apr
(6) |
May
|
Jun
(3) |
Jul
(11) |
Aug
(1) |
Sep
|
Oct
(15) |
Nov
(1) |
Dec
(5) |
2011 |
Jan
(4) |
Feb
(1) |
Mar
(6) |
Apr
|
May
(22) |
Jun
|
Jul
(8) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
2012 |
Jan
|
Feb
(10) |
Mar
(1) |
Apr
(6) |
May
(27) |
Jun
(48) |
Jul
(30) |
Aug
(4) |
Sep
|
Oct
(3) |
Nov
(1) |
Dec
(11) |
2013 |
Jan
(4) |
Feb
(7) |
Mar
(6) |
Apr
(18) |
May
(28) |
Jun
(20) |
Jul
|
Aug
(4) |
Sep
(1) |
Oct
(1) |
Nov
(2) |
Dec
(7) |
2014 |
Jan
(3) |
Feb
(2) |
Mar
(4) |
Apr
(9) |
May
(11) |
Jun
(10) |
Jul
|
Aug
(18) |
Sep
(12) |
Oct
(17) |
Nov
(10) |
Dec
(16) |
2015 |
Jan
(5) |
Feb
(1) |
Mar
(5) |
Apr
(4) |
May
(28) |
Jun
(2) |
Jul
|
Aug
|
Sep
(6) |
Oct
|
Nov
(2) |
Dec
(1) |
2016 |
Jan
(14) |
Feb
|
Mar
(3) |
Apr
|
May
|
Jun
(3) |
Jul
(4) |
Aug
(4) |
Sep
(1) |
Oct
(1) |
Nov
|
Dec
(1) |
2017 |
Jan
(11) |
Feb
|
Mar
(21) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
(2) |
Sep
(4) |
Oct
(4) |
Nov
|
Dec
(1) |
2019 |
Jan
(1) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(13) |
Sep
(4) |
Oct
|
Nov
|
Dec
|
2020 |
Jan
(10) |
Feb
(9) |
Mar
(5) |
Apr
(4) |
May
(3) |
Jun
(18) |
Jul
(4) |
Aug
(2) |
Sep
(20) |
Oct
(2) |
Nov
|
Dec
|
2021 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
(1) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
2022 |
Jan
(1) |
Feb
(2) |
Mar
(2) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(5) |
Sep
|
Oct
(1) |
Nov
|
Dec
(1) |
2023 |
Jan
(10) |
Feb
(7) |
Mar
(29) |
Apr
(31) |
May
(29) |
Jun
(34) |
Jul
(3) |
Aug
(24) |
Sep
(22) |
Oct
(10) |
Nov
(38) |
Dec
(27) |
2024 |
Jan
(15) |
Feb
(8) |
Mar
(4) |
Apr
(20) |
May
(33) |
Jun
(18) |
Jul
(15) |
Aug
(23) |
Sep
(26) |
Oct
(32) |
Nov
(6) |
Dec
(4) |
2025 |
Jan
(7) |
Feb
(1) |
Mar
(1) |
Apr
(4) |
May
(46) |
Jun
(19) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <at...@us...> - 2007-08-23 23:28:56
|
Revision: 490 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=490&view=rev Author: atani Date: 2007-08-23 16:28:54 -0700 (Thu, 23 Aug 2007) Log Message: ----------- file not File Modified Paths: -------------- tiki/include/Tiki/net/buffer.h Modified: tiki/include/Tiki/net/buffer.h =================================================================== --- tiki/include/Tiki/net/buffer.h 2007-08-23 22:59:57 UTC (rev 489) +++ tiki/include/Tiki/net/buffer.h 2007-08-23 23:28:54 UTC (rev 490) @@ -9,7 +9,7 @@ #define __TIKI_NET_BUFFER_H #include "Tiki/object.h" -#include "Tiki/File.h" +#include "Tiki/file.h" #include <fstream> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-23 23:00:00
|
Revision: 489 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=489&view=rev Author: atani Date: 2007-08-23 15:59:57 -0700 (Thu, 23 Aug 2007) Log Message: ----------- fixes for POST and uploading file(s). a few cleanups of RefPtr uses, still have some problems with memory leaks in HttpUserAgent Modified Paths: -------------- tiki/examples/net/chatd/src/main.cpp tiki/examples/net/httpclient/src/main.cpp tiki/include/Tiki/net/address.h tiki/include/Tiki/net/buffer.h tiki/include/Tiki/net/http/request.h tiki/include/Tiki/net/http/useragent.h tiki/include/Tiki/net/socket.h tiki/include/Tiki/net/tcpserversocket.h tiki/include/Tiki/net/tcpsocket.h tiki/src/net/http/request.cpp tiki/src/net/http/useragent.cpp tiki/src/net/socket.cpp tiki/src/net/tcpserversocket.cpp tiki/src/net/tcpsocket.cpp Modified: tiki/examples/net/chatd/src/main.cpp =================================================================== --- tiki/examples/net/chatd/src/main.cpp 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/examples/net/chatd/src/main.cpp 2007-08-23 22:59:57 UTC (rev 489) @@ -82,7 +82,7 @@ { uint8 *data = line->getData(); string cmd = ""; - for(int i = 0; i < line->getUsedDataLen(); i++) + for(size_t i = 0; i < line->getUsedDataLen(); i++) { cmd.push_back(data[i]); } Modified: tiki/examples/net/httpclient/src/main.cpp =================================================================== --- tiki/examples/net/httpclient/src/main.cpp 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/examples/net/httpclient/src/main.cpp 2007-08-23 22:59:57 UTC (rev 489) @@ -31,17 +31,12 @@ Tiki::Net::init(); Hid::callbackReg( tkCallback, NULL ); - if(argc < 2) { - Tiki::Debug::printf("Need to pass request url on commandline\n"); - return -1; - } - RefPtr<HttpUserAgent> useragent = new HttpUserAgent(); //useragent->setProxyHost("proxy.example.com"); //useragent->setProxyPort(80); RefPtr<Request> request = new Request(); - request->setUrl(argv[1]); + request->setUrl("http://www.example.com/"); RefPtr<Response> response = useragent->get(request); Tiki::Debug::printf("response code: %d\n", response->getResultCode()); @@ -51,12 +46,12 @@ iter != content.end(); ++iter) { - RefPtr<Buffer> responseBuf = response->getContentPart(*iter); + Buffer *responseBuf = response->getContentPart(*iter); Tiki::Debug::printf("Content Part: %s [%u bytes]\n", (*iter).c_str(), responseBuf->getUsedDataLen()); Tiki::Debug::printf("%s\n", responseBuf->getData()); } - Tiki::Net::shutdown(); + return 0; } Modified: tiki/include/Tiki/net/address.h =================================================================== --- tiki/include/Tiki/net/address.h 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/include/Tiki/net/address.h 2007-08-23 22:59:57 UTC (rev 489) @@ -18,6 +18,9 @@ { public: Address(); + Address(std::string hostname, int port) : m_port(port) { + setHostName(hostname); + } typedef enum AddressType { AddressUnknown = 0x00000000, Modified: tiki/include/Tiki/net/buffer.h =================================================================== --- tiki/include/Tiki/net/buffer.h 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/include/Tiki/net/buffer.h 2007-08-23 22:59:57 UTC (rev 489) @@ -22,14 +22,16 @@ class Buffer : public Object { public: - Buffer(size_t len, std::string contentType = "application/octet-stream") : m_contentType(contentType) { + Buffer(size_t len, std::string contentType = "application/octet-stream") : + m_contentType(contentType) { m_data = new uint8[len]; memset(m_data, 0, len); m_dataLen = len; m_usedDataLen = 0; } - Buffer(size_t len, uint8 *data, std::string contentType = "application/octet-stream") : m_contentType(contentType) { + Buffer(size_t len, uint8 *data, std::string contentType = "application/octet-stream") : + m_contentType(contentType) { m_data = new uint8[len]; memset(m_data, 0, len); m_dataLen = len; @@ -39,13 +41,9 @@ Buffer(std::string filename, std::string contentType, std::string fieldName = "") : m_fileName(filename), m_contentType(contentType), m_fieldName(fieldName) { - std::ifstream stream(filename.c_str(), std::ios::in | std::ios::binary); - stream.seekg(0, std::ios::end); - m_dataLen = m_usedDataLen = stream.tellg(); - stream.seekg(0); - m_data = new uint8[m_dataLen]; - stream.read((char *)m_data, m_dataLen); - stream.close(); + File file(filename, "rb"); + read(file); + file.close(); } Buffer(Tiki::File file, std::string contentType, std::string fieldName = "") : @@ -58,12 +56,12 @@ m_fileName = file.getFileName(); m_dataLen = m_usedDataLen = file.total(); m_data = new uint8[m_dataLen]; - file.read(m_data, m_dataLen); + file.read(m_data, static_cast<int>(m_dataLen)); } void write(Tiki::File file) { assert(file.isValid()); - file.write(m_data, m_usedDataLen); + file.write(m_data, static_cast<int>(m_usedDataLen)); } void append(RefPtr<Buffer> buf) { Modified: tiki/include/Tiki/net/http/request.h =================================================================== --- tiki/include/Tiki/net/http/request.h 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/include/Tiki/net/http/request.h 2007-08-23 22:59:57 UTC (rev 489) @@ -1,61 +1,74 @@ -/* - Tiki - - useragent.h - - Copyright (C)2007 Atani Software -*/ -#ifndef __TIKI_NET_HTTP_REQUEST_H -#define __TIKI_NET_HTTP_REQUEST_H - -#include "Tiki/refcnt.h" - -namespace Tiki { - -namespace Net { - -namespace Http { - -extern std::string DEFAULT_CONTENT_PART; - -class Request : public RefCnt { - public: - Request(); - - std::string getUrl() const { - return m_url; - } - - void setUrl(string url) { - m_url = url; - } - - void removeHeaderParam(std::string param); - void setHeaderParam(std::string param, std::string value); - std::string getHeaderParam(std::string param) const; - std::list<std::string> getHeaderParamNames() const; - - void addContentPart(std::string name, RefPtr<Buffer> input); - std::list<std::string> getContentPartNames() const; - RefPtr<Buffer> getContentPart(std::string name) const; - - std::string getBoundaryMarker() const { - return m_boundaryMarker; - } - - private: - std::string m_url; - std::string m_boundaryMarker; - typedef std::map<std::string, std::string> StringStringMap; - typedef std::map<std::string, RefPtr< Buffer > > StringBufferMap; - StringStringMap m_params; - StringBufferMap m_parts; -}; - -}; // namespace Http - -}; // namespace Net - -}; // namespace Tiki - -#endif // __TIKI_NET_HTTP_REQUEST_H +/* + Tiki + + useragent.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_HTTP_REQUEST_H +#define __TIKI_NET_HTTP_REQUEST_H + +#include "Tiki/refcnt.h" + +namespace Tiki { + +namespace Net { + +namespace Http { + +extern std::string DEFAULT_CONTENT_PART; + +class Request : public RefCnt { + public: + Request(); + /* + virtual ~Request() { + m_params.clear(); + if(!m_parts.empty()) { + for(StringBufferMap::iterator iter = m_parts.begin(); + iter != m_parts.end(); + ++iter) { + delete iter->second; + } + } + m_parts.clear(); + } + */ + + std::string getUrl() const { + return m_url; + } + + void setUrl(string url) { + m_url = url; + } + + void removeHeaderParam(std::string param); + void setHeaderParam(std::string param, std::string value); + std::string getHeaderParam(std::string param) const; + std::list<std::string> getHeaderParamNames() const; + + void addContentPart(Buffer *input, std::string name = ""); + std::list<std::string> getContentPartNames() const; + Buffer *getContentPart(std::string name) const; + + std::string getBoundaryMarker() const { + return m_boundaryMarker; + } + + private: + std::string m_url; + std::string m_boundaryMarker; + typedef std::map<std::string, std::string> StringStringMap; + typedef std::map<std::string, RefPtr<Buffer> > StringBufferMap; + StringStringMap m_params; + StringBufferMap m_parts; +}; + +}; // namespace Http + +}; // namespace Net + +}; // namespace Tiki + +#endif // __TIKI_NET_HTTP_REQUEST_H Modified: tiki/include/Tiki/net/http/useragent.h =================================================================== --- tiki/include/Tiki/net/http/useragent.h 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/include/Tiki/net/http/useragent.h 2007-08-23 22:59:57 UTC (rev 489) @@ -1,82 +1,89 @@ -/* - Tiki - - useragent.h - - Copyright (C)2007 Atani Software -*/ -#ifndef __TIKI_NET_HTTP_USERAGENT_H -#define __TIKI_NET_HTTP_USERAGENT_H - -#include "Tiki/refcnt.h" -#include "Tiki/net/tcpsocket.h" -#include "Tiki/net/http/cookie.h" -#include "Tiki/net/http/request.h" -#include "Tiki/net/http/response.h" - -namespace Tiki { - -namespace Net { - -namespace Http { - -using Tiki::Net::TCP::TCPSocket; - -class HttpUserAgent : public RefCnt { - - public: - HttpUserAgent(); - - void setUserAgentName(std::string name) { - m_userAgentName = name; - } - - std::string getUserAgentName() const { - return m_userAgentName; - } - - void setProxyHost(std::string host) { - m_proxyHost = host; - } - - std::string getProxyHost() const { - return m_proxyHost; - } - - void setProxyPort(int port) { - m_proxyPort = port; - } - - int getProxyPort() const { - return m_proxyPort; - } - - std::list< RefPtr< Cookie > > getCookies() const { - return m_cookies; - } - - RefPtr<Response> get(RefPtr<Request> req); - - RefPtr<Response> post(RefPtr<Request> req); - - private: - std::string m_userAgentName; - std::string m_proxyHost; - int m_proxyPort; - std::list< RefPtr< Cookie > > m_cookies; - - void parseUrl(const std::string url, std::string &host, std::string &resource, int &port); - void buildRequest(const std::string host, const std::string resource, const int port, - const std::string mode, RefPtr<Request> request, std::string &requestText, - RefPtr<Address> address); - void readResponse(RefPtr<Response> response, RefPtr<TCPSocket> socket); - -}; - -}; // namespace Http - -}; // namespace Net - -}; // namespace Tiki - -#endif // __TIKI_NET_HTTP_USERAGENT_H +/* + Tiki + + useragent.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_HTTP_USERAGENT_H +#define __TIKI_NET_HTTP_USERAGENT_H + +#include "Tiki/refcnt.h" +#include "Tiki/net/tcpsocket.h" +#include "Tiki/net/http/cookie.h" +#include "Tiki/net/http/request.h" +#include "Tiki/net/http/response.h" + +namespace Tiki { + +namespace Net { + +namespace Http { + +using Tiki::Net::TCP::TCPSocket; + +class HttpUserAgent : public RefCnt { + + public: + HttpUserAgent(); + virtual ~HttpUserAgent() { + for(std::list< RefPtr< Cookie > >::iterator iter = m_cookies.begin(); + iter != m_cookies.end(); + ++iter) { + delete *iter; + } + m_cookies.clear(); + } + + void setUserAgentName(std::string name) { + m_userAgentName = name; + } + + std::string getUserAgentName() const { + return m_userAgentName; + } + + void setProxyHost(std::string host) { + m_proxyHost = host; + } + + std::string getProxyHost() const { + return m_proxyHost; + } + + void setProxyPort(int port) { + m_proxyPort = port; + } + + int getProxyPort() const { + return m_proxyPort; + } + + std::list< RefPtr< Cookie > > getCookies() const { + return m_cookies; + } + + Response *get(Request *req); + + Response *post(Request *req); + + private: + std::string m_userAgentName; + std::string m_proxyHost; + int m_proxyPort; + std::list< RefPtr< Cookie > > m_cookies; + + void parseUrl(const std::string url, std::string &host, std::string &resource, int &port); + void buildRequest(const std::string host, const std::string resource, const int port, + const std::string mode, Request *request, std::string &requestText); + void readResponse(Response *response, TCPSocket *socket); + +}; + +}; // namespace Http + +}; // namespace Net + +}; // namespace Tiki + +#endif // __TIKI_NET_HTTP_USERAGENT_H Modified: tiki/include/Tiki/net/socket.h =================================================================== --- tiki/include/Tiki/net/socket.h 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/include/Tiki/net/socket.h 2007-08-23 22:59:57 UTC (rev 489) @@ -20,24 +20,24 @@ { public: Socket(); - Socket(RefPtr<Address> address); + Socket(Address *address); - RefPtr<Address> getPeerAddress() + Address *getPeerAddress() { return m_peerAddress; } - void setPeerAddress(RefPtr<Address> address) + void setPeerAddress(Address *address) { m_peerAddress = address; } - RefPtr<Address> getLocalAddress() + Address *getLocalAddress() { return m_localAddress; } - void setLocalAddress(RefPtr<Address> address) + void setLocalAddress(Address *address) { m_localAddress = address; } @@ -62,9 +62,9 @@ m_reuse = reuse; } - virtual void send(RefPtr<Buffer> data) = 0; + virtual void send(Buffer *data) = 0; - virtual void recv(RefPtr<Buffer> data) = 0; + virtual void recv(Buffer *data) = 0; virtual void open() = 0; Modified: tiki/include/Tiki/net/tcpserversocket.h =================================================================== --- tiki/include/Tiki/net/tcpserversocket.h 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/include/Tiki/net/tcpserversocket.h 2007-08-23 22:59:57 UTC (rev 489) @@ -20,11 +20,11 @@ { public: TCPServerSocket() : TCPSocket() {}; - TCPServerSocket(RefPtr<Address> address) : TCPSocket(address) {}; + TCPServerSocket(Address *address) : TCPSocket(address) {}; void bind(size_t maxwaiting = 10); - RefPtr<TCPSocket> accept(); + TCPSocket *accept(); }; } // namespace TCP Modified: tiki/include/Tiki/net/tcpsocket.h =================================================================== --- tiki/include/Tiki/net/tcpsocket.h 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/include/Tiki/net/tcpsocket.h 2007-08-23 22:59:57 UTC (rev 489) @@ -32,27 +32,27 @@ #define SOCKET_ERROR -1 #endif TCPSocket() : Socket(), m_open(false) {}; - TCPSocket(RefPtr<Address> address) : Socket(address), m_open(false) {}; + TCPSocket(Address *address) : Socket(address), m_open(false) {}; #if TIKI_PLAT == TIKI_WIN32 - TCPSocket(RefPtr<Address> address, SOCKET socket) : Socket(address), m_socket(socket), m_open(true) {setNonBlocking(false);}; + TCPSocket(Address *address, SOCKET socket) : Socket(address), m_socket(socket), m_open(true) {setNonBlocking(false);}; #else TCPSocket(RefPtr<Address> address, int socket) : Socket(address), m_socket(socket), m_open(true) {setNonBlocking(false);}; #endif - virtual void send(RefPtr<Buffer> data); + virtual void send(Buffer *data); - virtual void recv(RefPtr<Buffer> data); + virtual void recv(Buffer *data); virtual bool isOpen() { return m_open; } - uint32 getPort() + uint16 getPort() { return m_port; } - void setPort(uint32 port) + void setPort(uint16 port) { m_port = port; } @@ -63,7 +63,7 @@ virtual void setNonBlocking(bool blocking); protected: - uint32 m_port; + uint16 m_port; bool m_open; #if TIKI_PLAT == TIKI_WIN32 SOCKET m_socket; Modified: tiki/src/net/http/request.cpp =================================================================== --- tiki/src/net/http/request.cpp 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/src/net/http/request.cpp 2007-08-23 22:59:57 UTC (rev 489) @@ -1,96 +1,100 @@ -/* - Tiki - - request.cpp - - Copyright (C)2007 Atani Software -*/ - -#include "pch.h" -#include "Tiki/tiki.h" -#include "Tiki/net.h" -#include "Tiki/net/http/request.h" - -namespace Tiki { - -namespace Net { - -namespace Http { - -std::string DEFAULT_CONTENT_PART = "__TIKI__DEFAULT__"; - -Request::Request() { - setHeaderParam("Connection", "close"); - m_boundaryMarker = "-----------------------09f911019d74e35bd84156c5635688c0"; - -} - -void Request::removeHeaderParam(std::string param) { - if(m_params.find(param) != m_params.end()) { - m_params.erase(m_params.find(param)); - } -} - -void Request::setHeaderParam(std::string param, std::string value) { - if(!param.compare("User-Agent")) { - Tiki::Debug::printf("Setting User-Agent via Request::setHeaderParam() is not allowed. Use HttpUserAgent::setUserAgentName() instead.\n"); - return; - } - m_params.insert(std::make_pair(param, value)); -} - -std::string Request::getHeaderParam(std::string param) const { - if(m_params.find(param) != m_params.end()) { - return m_params.find(param)->second; - } - return ""; -} - -std::list<std::string> Request::getHeaderParamNames() const { - std::list<std::string> params; - - for( StringStringMap::const_iterator param = m_params.begin(); - param != m_params.end(); - ++param) { - - params.push_back(param->first); - } - - return params; -} - -void Request::addContentPart(std::string name, RefPtr<Buffer> input) { - //if(m_parts.find(name) != m_parts.end()) { - // m_parts.erase(m_parts.find(name)); - //} - - m_parts.insert(std::make_pair(name, input)); -} - -RefPtr<Buffer> Request::getContentPart(std::string name) const { - if(m_parts.find(name) != m_parts.end()) { - return m_parts.find(name)->second; - } - return NULL; -} - -std::list<std::string> Request::getContentPartNames() const { - std::list<std::string> parts; - - for( StringBufferMap::const_iterator part = m_parts.begin(); - part != m_parts.end(); - ++part) { - - parts.push_back(part->first); - } - - return parts; -} - - -}; // namespace Http - -}; // namespace Net - -}; // namespace Tiki - +/* + Tiki + + request.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "pch.h" +#include "Tiki/tiki.h" +#include "Tiki/net.h" +#include "Tiki/net/http/request.h" + +namespace Tiki { + +namespace Net { + +namespace Http { + +std::string DEFAULT_CONTENT_PART = "__TIKI__DEFAULT__"; + +Request::Request() { + setHeaderParam("Connection", "close"); + m_boundaryMarker = "-----------------------09f911019d74e35bd84156c5635688c0"; + +} + +void Request::removeHeaderParam(std::string param) { + if(m_params.find(param) != m_params.end()) { + m_params.erase(m_params.find(param)); + } +} + +void Request::setHeaderParam(std::string param, std::string value) { + if(!param.compare("User-Agent")) { + Tiki::Debug::printf("Setting User-Agent via Request::setHeaderParam() is not allowed. Use HttpUserAgent::setUserAgentName() instead.\n"); + return; + } + m_params.insert(std::make_pair(param, value)); +} + +std::string Request::getHeaderParam(std::string param) const { + if(m_params.find(param) != m_params.end()) { + return m_params.find(param)->second; + } + return ""; +} + +std::list<std::string> Request::getHeaderParamNames() const { + std::list<std::string> params; + + for( StringStringMap::const_iterator param = m_params.begin(); + param != m_params.end(); + ++param) { + + params.push_back(param->first); + } + + return params; +} + +void Request::addContentPart(Buffer *input, std::string name) { + if(!name.empty()) { + m_parts.insert(std::make_pair(name, input)); + } + else if(!input->getFileName().empty()) { + m_parts.insert(std::make_pair(input->getFileName(), input)); + } + else { + m_parts.insert(std::make_pair(DEFAULT_CONTENT_PART, input)); + } +} + +Buffer *Request::getContentPart(std::string name) const { + if(m_parts.find(name) != m_parts.end()) { + return m_parts.find(name)->second; + } + return NULL; +} + +std::list<std::string> Request::getContentPartNames() const { + std::list<std::string> parts; + + for( StringBufferMap::const_iterator part = m_parts.begin(); + part != m_parts.end(); + ++part) { + + parts.push_back(part->first); + } + + return parts; +} + + +}; // namespace Http + +}; // namespace Net + +}; // namespace Tiki + Modified: tiki/src/net/http/useragent.cpp =================================================================== --- tiki/src/net/http/useragent.cpp 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/src/net/http/useragent.cpp 2007-08-23 22:59:57 UTC (rev 489) @@ -1,397 +1,396 @@ -/* - Tiki - - useragent.cpp - - Copyright (C)2007 Atani Software -*/ - -#include "pch.h" -#include "Tiki/tiki.h" -#include "Tiki/net.h" -#include "Tiki/net/http/useragent.h" - -#include <sstream> -#include <math.h> - -namespace Tiki { - -namespace Net { - -namespace Http { - -using namespace Tiki::Net::TCP; - -#define READ_ONE_LINE(res, socket) \ - { \ - RefPtr<Buffer> recvBuf = new Buffer(1); \ - char tbuf[2]; \ - res = ""; \ - while(socket->isOpen()) { \ - recvBuf->reset(); \ - socket->recv(recvBuf); \ - if(recvBuf->getUsedDataLen() > 0) { \ - tbuf[0] = recvBuf->getData()[0]; \ - tbuf[1] = '\0'; \ - if(tbuf[0] != '\n' && tbuf[0] != '\r' ) { \ - res.append((char *)tbuf); \ - } \ - else if(tbuf[0] != '\r' ) { \ - break; \ - } \ - } \ - } \ - } - -HttpUserAgent::HttpUserAgent() { -#if TIKI_PLAT == TIKI_WIN32 - setUserAgentName("Tiki/1.0 (Windows)"); -#elif TIKI_PLAT == TIKI_NDS - setUserAgentName("Tiki/1.0 (Nintendo DS)"); -#elif TIKI_PLAT == TIKI_SDL - setUserAgentName("Tiki/1.0 (SDL)"); -#elif TIKI_PLAT == TIKI_OSX - setUserAgentName("Tiki/1.0 (Mac OS X)"); -#else - setUserAgentName("Tiki/1.0 (Unknown)"); -#endif - setProxyHost(""); - setProxyPort(8080); -} - -RefPtr<Response> HttpUserAgent::get(RefPtr<Request> req) { - RefPtr<TCPSocket> socket = new TCPSocket(); - socket->setNonBlocking(false); - RefPtr<Response> response = new Response(); - response->setUrl(req->getUrl()); - response->setResultCode(200); - - std::string hostname; - int port; - std::string resource; - - parseUrl(req->getUrl(), hostname, resource, port); - - RefPtr<Address> requestAddress = new Address(); - - std::string requestText; - buildRequest(hostname, resource, port, "GET", req, requestText, requestAddress); - socket->setPeerAddress(requestAddress); - Tiki::Debug::printf("Request:\n%s", requestText.c_str()); - - socket->open(); - if(socket->isOpen()) { - Tiki::Debug::printf("Sending request...\n"); - } - else { - Tiki::Debug::printf("connect failed\n"); - response->setResultCode(504); - return response; - } - - RefPtr<Buffer> buf = new Buffer(2048); - buf->setData((uint8 *)requestText.c_str(), requestText.length()); - socket->send(buf); - - readResponse(response, socket); - - return response; -} - -RefPtr<Response> HttpUserAgent::post(RefPtr<Request> req) { - RefPtr<TCPSocket> socket = new TCPSocket(); - socket->setNonBlocking(false); - RefPtr<Response> response = new Response(); - response->setUrl(req->getUrl()); - response->setResultCode(200); - - std::string hostname; - int port; - std::string resource; - - parseUrl(req->getUrl(), hostname, resource, port); - - RefPtr<Address> requestAddress = new Address(); - - std::string requestText; - buildRequest(hostname, resource, port, "POST", req, requestText, requestAddress); - socket->setPeerAddress(requestAddress); - Tiki::Debug::printf("Request:\n%s", requestText.c_str()); - - socket->open(); - if(socket->isOpen()) { - Tiki::Debug::printf("Sending request...\n"); - } - else { - Tiki::Debug::printf("connect failed\n"); - response->setResultCode(504); - return response; - } - - RefPtr<Buffer> buf = new Buffer(2048); - buf->setData((uint8 *)requestText.c_str(), requestText.length()); - socket->send(buf); - - std::list<std::string> content = req->getContentPartNames(); - if(content.size() > 1) { - for(std::list<std::string>::iterator iter = content.begin(); - iter != content.end(); - ++iter) { - RefPtr<Buffer> buf = req->getContentPart(*iter); - std::stringstream temp; - temp << req->getBoundaryMarker() << "\r\n"; - temp << "Content-Disposition: form-data: name=\""; - if(!buf->getFieldName().empty()) { - temp << buf->getFieldName(); - } - else { - temp << "File"; - } - temp << "\"; filename=\"" << buf->getFileNameShort() << "\"\r\nContent-Type: " << buf->getContentType() << "\r\n"; - RefPtr<Buffer> headerBuf = new Buffer(2048); - std::string headerText = temp.str(); - headerBuf->setData((uint8 *)headerText.c_str(), headerText.length()); - socket->send(headerBuf); - socket->send(buf); - } - std::string footerText = "--"; - footerText.append(req->getBoundaryMarker()); - footerText.append("--\r\n"); - RefPtr<Buffer> footerBuf = new Buffer(2048); - footerBuf->setData((uint8 *)footerText.c_str(), footerText.length()); - socket->send(footerBuf); - } - else if(content.size() == 1) { - RefPtr<Buffer> buf = req->getContentPart(*content.begin()); - socket->send(buf); - } - - readResponse(response, socket); - - return response; -} - -void HttpUserAgent::parseUrl(const std::string url, std::string &host, std::string &resource, int &port) { - std::string temp_url = url; - - // set defaults - host = ""; - port = 80; - resource = "/index.html"; - - if(temp_url.find("http://") == 0) { - temp_url = temp_url.substr(std::string("http://").length()); - } - else if(temp_url.find("https://") == 0) { - temp_url = temp_url.substr(std::string("https://").length()); - } - host = temp_url.substr(0, temp_url.find("/")); - if(temp_url.find("/") != std::string::npos) { - resource = temp_url.substr(temp_url.find("/")); - } - if(host.find(":") != std::string::npos) { - std::string portstr = url.substr(host.find(":")); - port = atoi(portstr.c_str()); - host = host.substr(0, host.find(":")); - } -} - -void HttpUserAgent::buildRequest(const std::string host, const std::string resource, const int port, - const std::string mode, RefPtr<Request> request, std::string &requestText, - RefPtr<Address> address) { - - std::stringstream req; - if(m_proxyHost.empty()) { - req << mode << " " << resource << " HTTP/1.1\r\n"; - req << "Host: " << host << "\r\n"; - address->setHostName(host); - address->setPort(port); - } - else { - // proxy connection - req << mode << " " << request->getUrl(); - if(port != 80) { - req << ":" << port; - } - req << " HTTP/1.1\r\n"; - req << "Host: " << host << "\r\n"; - address->setHostName(m_proxyHost); - address->setPort(m_proxyPort); - } - std::list<std::string> params = request->getHeaderParamNames(); - for(std::list<string>::const_iterator param = params.begin(); - param != params.end(); - ++param) { - req << *param << ": " << request->getHeaderParam(*param) << "\r\n"; - } - - if(!m_userAgentName.empty()) { - req << "User-Agent: " << m_userAgentName << "\r\n"; - } - - std::list<std::string> content = request->getContentPartNames(); - if(!mode.compare("POST") && content.size() > 1) { - uint64 totalSize = request->getBoundaryMarker().length() + 6; // add 6 to account for "--<boundary>--\r\n" - for(std::list<std::string>::iterator iter = content.begin(); - iter != content.end(); - ++iter) { - RefPtr<Buffer> buf = request->getContentPart(*iter); - totalSize += buf->getUsedDataLen(); - std::stringstream temp; - temp << "Content-Disposition: form-data: name=\""; - if(!buf->getFieldName().empty()) { - temp << buf->getFieldName(); - } - else { - temp << "File"; - } - temp << "\"; filename=\"" << buf->getFileNameShort() << "\"\r\nContent-Type: " << buf->getContentType() << "\r\n"; - - // add section header size - totalSize += temp.str().length(); - } - - req << "Content-Length: " << totalSize << "\r\n"; - req << "Expect: 100-continue\r\n"; - req << "Content-Type: multipart/form-data; boundary=" << request->getBoundaryMarker() << "\r\n"; - } - else if(!mode.compare("POST") && content.size() == 1) { - RefPtr<Buffer> buf = request->getContentPart(*content.begin()); - req << "Content-Type: " << buf->getContentType() << "\r\n"; - req << "Content-Length: " << buf->getUsedDataLen() << "\r\n"; - } - req << "\r\n"; - - requestText = req.str(); -} - -void HttpUserAgent::readResponse(RefPtr<Response> response, RefPtr<TCPSocket> socket) { - std::string status = ""; - READ_ONE_LINE(status, socket) - - //Tiki::Debug::printf("Status: %s\n", status.c_str()); - for(int i = 0; i < status.length(); i++) { - if(status.at(i) == ' ') { - response->setResultCode(atoi(status.c_str()+i + 1)); - break; - } - } - - while(1) { - std::string line = ""; - READ_ONE_LINE(line, socket) - if(line.size() == 0) { - // done with headers - break; - } - //Tiki::Debug::printf("HEADER_LINE: %s\n", line.c_str()); - if(line.find(":") != std::string::npos) { - std::string field = line.substr(0, line.find(":")); - std::string value = line.substr(line.find(":") + 1); - while(value.at(0) == ' ') { - value = value.substr(1); - } - - if(!field.compare("Set-Cookie")) { - - } - else { - response->setHeaderParam(field, value); - } - } - } - - RefPtr<Buffer> fullBuf = new Buffer(1); - - if(!response->getHeaderParam("Transfer-Encoding").compare("chunked")) { - Tiki::Debug::printf("Encoding is chunked\n"); - // evil chunked encoding - size_t totalSize = 0; - - long sizeDecoded = 0; - do - { - sizeDecoded = 0; - std::string size = ""; - READ_ONE_LINE(size, socket); - if(size.empty()) { - sizeDecoded = 1; - continue; - } - - while(size.find(" ") != std::string::npos) { - size.erase(size.find(" "), 1); - } - - int base = 1; - for(int i = 0; i < size.length(); i++ ) { - char ch = size.at(i); - if(ch >= 'A' && ch <= 'F') { - ch -= 'A'; - ch += 10; - } - else if(ch >= 'a' && ch <= 'f') { - ch -= 'a'; - ch += 10; - } - else if(ch >= '0' && ch <= '9') { - ch -= '0'; - } - else { - continue; - } - sizeDecoded += (ch * static_cast<int>(pow(16.0f, static_cast<int>(size.length() - i - 1)))); - } - //Tiki::Debug::printf("chunk size: %d [%s]\n", sizeDecoded, size.c_str()); - if(sizeDecoded > 0) { - - RefPtr<Buffer> chunkBuf = new Buffer(sizeDecoded); - socket->recv(chunkBuf); - if(chunkBuf->getUsedDataLen() < sizeDecoded) - { - //Tiki::Debug::printf("Buffer underflow\n"); - int needed = sizeDecoded - chunkBuf->getUsedDataLen(); - while(needed > 0) { - RefPtr<Buffer> chunkBuf2 = new Buffer(needed); - socket->recv(chunkBuf2); - chunkBuf->append(chunkBuf2); - needed -= chunkBuf2->getUsedDataLen(); - } - } - totalSize += chunkBuf->getUsedDataLen(); - fullBuf->append(chunkBuf); - } - } while(sizeDecoded > 0); - //Tiki::Debug::printf("total size: %d %x\n", totalSize, totalSize); - } - else if(response->getHeaderParam("Content-Length").compare("")) { - Tiki::Debug::printf("Encoding is inline\n"); - long sizeDecoded = atoi(response->getHeaderParam("Content-Length").c_str()); - //Tiki::Debug::printf("decodedSize: %d\n", sizeDecoded); - - RefPtr<Buffer> chunkBuf = new Buffer(sizeDecoded); - socket->recv(chunkBuf); - if(chunkBuf->getUsedDataLen() < sizeDecoded) - { - sizeDecoded -= chunkBuf->getUsedDataLen(); - while(sizeDecoded > 0) { - RefPtr<Buffer> chunkBuf2 = new Buffer(sizeDecoded); - socket->recv(chunkBuf2); - chunkBuf->append(chunkBuf2); - sizeDecoded -= chunkBuf2->getUsedDataLen(); - } - } - fullBuf->append(chunkBuf); - } - else { - Tiki::Debug::printf("Encoding is unknown\n"); - } - response->addContentPart(DEFAULT_CONTENT_PART, fullBuf); -} - -}; // namespace Http - -}; // namespace Net - -}; // namespace Tiki - +/* + Tiki + + useragent.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "pch.h" +#include "Tiki/tiki.h" +#include "Tiki/net.h" +#include "Tiki/net/http/useragent.h" + +#include <sstream> +#include <math.h> + +namespace Tiki { + +namespace Net { + +namespace Http { + +using namespace Tiki::Net::TCP; + +#define READ_ONE_LINE(res, socket) \ + { \ + RefPtr<Buffer> recvBuf = new Buffer(1); \ + char tbuf[2]; \ + res = ""; \ + while(socket->isOpen()) { \ + recvBuf->reset(); \ + socket->recv(recvBuf); \ + if(recvBuf->getUsedDataLen() > 0) { \ + tbuf[0] = recvBuf->getData()[0]; \ + tbuf[1] = '\0'; \ + if(tbuf[0] != '\n' && tbuf[0] != '\r' ) { \ + res.append((char *)tbuf); \ + } \ + else if(tbuf[0] != '\r' ) { \ + break; \ + } \ + } \ + } \ + } + +HttpUserAgent::HttpUserAgent() { +#if TIKI_PLAT == TIKI_WIN32 + setUserAgentName("Tiki/1.0 (Windows)"); +#elif TIKI_PLAT == TIKI_NDS + setUserAgentName("Tiki/1.0 (Nintendo DS)"); +#elif TIKI_PLAT == TIKI_SDL + setUserAgentName("Tiki/1.0 (SDL)"); +#elif TIKI_PLAT == TIKI_OSX + setUserAgentName("Tiki/1.0 (Mac OS X)"); +#else + setUserAgentName("Tiki/1.0 (Unknown)"); +#endif + setProxyHost(""); + setProxyPort(8080); +} + +Response *HttpUserAgent::get(Request *req) { + + Response *response = new Response(); + response->setUrl(req->getUrl()); + response->setResultCode(200); + + std::string hostname; + int port; + std::string resource; + + parseUrl(req->getUrl(), hostname, resource, port); + + std::string requestText; + buildRequest(hostname, resource, port, "GET", req, requestText); + Tiki::Debug::printf("Request:\n%s", requestText.c_str()); + + RefPtr<TCPSocket> socket; + if(m_proxyHost.empty()) { + socket = new TCPSocket(new Address(hostname, port)); + } + else { + socket = new TCPSocket(new Address(m_proxyHost, m_proxyPort)); + } + + socket->setNonBlocking(false); + + socket->open(); + if(socket->isOpen()) { + Tiki::Debug::printf("Sending request...\n"); + } + else { + Tiki::Debug::printf("connect failed\n"); + response->setResultCode(504); + return response; + } + + RefPtr<Buffer> buf = new Buffer(2048); + buf->setData((uint8 *)requestText.c_str(), requestText.length()); + socket->send(buf); + + readResponse(response, socket); + + socket->close(); + + //delete socket; + + return response; +} + +Response *HttpUserAgent::post(Request *req) { + Response *response = new Response(); + response->setUrl(req->getUrl()); + response->setResultCode(200); + + std::string hostname; + int port; + std::string resource; + + parseUrl(req->getUrl(), hostname, resource, port); + + std::string requestText; + buildRequest(hostname, resource, port, "POST", req, requestText); + Tiki::Debug::printf("Request:\n%s", requestText.c_str()); + + RefPtr<TCPSocket> socket; + if(m_proxyHost.empty()) { + socket = new TCPSocket(new Address(hostname, port)); + } + else { + socket = new TCPSocket(new Address(m_proxyHost, m_proxyPort)); + } + + socket->setNonBlocking(false); + + socket->open(); + if(socket->isOpen()) { + Tiki::Debug::printf("Sending request...\n"); + } + else { + Tiki::Debug::printf("connect failed\n"); + response->setResultCode(504); + return response; + } + + RefPtr<Buffer> buf = new Buffer(2048); + buf->setData((uint8 *)requestText.c_str(), requestText.length()); + socket->send(buf); + + std::list<std::string> content = req->getContentPartNames(); + if(content.size() > 1) { + std::string status = ""; + READ_ONE_LINE(status, socket) + + for(std::list<std::string>::iterator iter = content.begin(); + iter != content.end(); + ++iter) { + RefPtr<Buffer> buf = req->getContentPart(*iter); + std::stringstream temp; + temp << req->getBoundaryMarker() << "\r\n"; + temp << "Content-Disposition: form-data: name=\""; + if(!buf->getFieldName().empty()) { + temp << buf->getFieldName(); + } + else { + temp << "File"; + } + temp << "\"; filename=\"" << buf->getFileNameShort() << "\"\r\nContent-Type: " << buf->getContentType() << "\r\n"; + RefPtr<Buffer> headerBuf = new Buffer(2048); + std::string headerText = temp.str(); + headerBuf->setData((uint8 *)headerText.c_str(), headerText.length()); + socket->send(headerBuf); + socket->send(buf); + } + std::string footerText = "--"; + footerText.append(req->getBoundaryMarker()); + footerText.append("--\r\n"); + RefPtr<Buffer> footerBuf = new Buffer(2048); + footerBuf->setData((uint8 *)footerText.c_str(), footerText.length()); + socket->send(footerBuf); + } + else if(content.size() == 1) { + RefPtr<Buffer> buf = req->getContentPart(*content.begin()); + socket->send(buf); + } + + readResponse(response, socket); + + socket->close(); + + //delete socket; + + return response; +} + +void HttpUserAgent::parseUrl(const std::string url, std::string &host, std::string &resource, int &port) { + std::string temp_url = url; + + // set defaults + host = ""; + port = 80; + resource = "/index.html"; + + if(temp_url.find("http://") == 0) { + temp_url = temp_url.substr(std::string("http://").length()); + } + else if(temp_url.find("https://") == 0) { + temp_url = temp_url.substr(std::string("https://").length()); + } + host = temp_url.substr(0, temp_url.find("/")); + if(temp_url.find("/") != std::string::npos) { + resource = temp_url.substr(temp_url.find("/")); + } + if(host.find(":") != std::string::npos) { + std::string portstr = url.substr(host.find(":")); + port = atoi(portstr.c_str()); + host = host.substr(0, host.find(":")); + } +} + +void HttpUserAgent::buildRequest(const std::string host, const std::string resource, const int port, + const std::string mode, Request *request, std::string &requestText) { + + std::stringstream req; + if(m_proxyHost.empty()) { + req << mode << " " << resource << " HTTP/1.1\r\n"; + req << "Host: " << host << "\r\n"; + } + else { + // proxy connection + req << mode << " " << request->getUrl(); + if(port != 80) { + req << ":" << port; + } + req << " HTTP/1.1\r\n"; + req << "Host: " << host << "\r\n"; + } + std::list<std::string> params = request->getHeaderParamNames(); + for(std::list<string>::const_iterator param = params.begin(); + param != params.end(); + ++param) { + req << *param << ": " << request->getHeaderParam(*param) << "\r\n"; + } + + if(!m_userAgentName.empty()) { + req << "User-Agent: " << m_userAgentName << "\r\n"; + } + + std::list<std::string> content = request->getContentPartNames(); + if(!mode.compare("POST") && content.size() > 1) { + uint64 totalSize = request->getBoundaryMarker().length() + 6; // add 6 to account for "--<boundary>--\r\n" + for(std::list<std::string>::iterator iter = content.begin(); + iter != content.end(); + ++iter) { + RefPtr<Buffer> buf = request->getContentPart(*iter); + totalSize += buf->getUsedDataLen(); + std::stringstream temp; + temp << "Content-Disposition: form-data: name=\""; + if(!buf->getFieldName().empty()) { + temp << buf->getFieldName(); + } + else { + temp << "File"; + } + temp << "\"; filename=\"" << buf->getFileNameShort() << "\"\r\nContent-Type: " << buf->getContentType() << "\r\n"; + + // add section header size + totalSize += temp.str().length(); + } + + req << "Content-Length: " << totalSize << "\r\n"; + req << "Expect: 100-continue\r\n"; + req << "Content-Type: multipart/form-data; boundary=" << request->getBoundaryMarker() << "\r\n"; + } + else if(!mode.compare("POST") && content.size() == 1) { + RefPtr<Buffer> buf = request->getContentPart(*content.begin()); + req << "Content-Type: " << buf->getContentType() << "\r\n"; + req << "Content-Length: " << buf->getUsedDataLen() << "\r\n"; + } + req << "\r\n"; + + requestText = req.str(); +} + +void HttpUserAgent::readResponse(Response *response, TCPSocket *socket) { + std::string status = ""; + READ_ONE_LINE(status, socket) + + //Tiki::Debug::printf("Status: %s\n", status.c_str()); + for(std::string::size_type i = 0; i < status.length(); i++) { + if(status.at(i) == ' ') { + response->setResultCode(atoi(status.c_str()+i + 1)); + break; + } + } + + while(1) { + std::string line = ""; + READ_ONE_LINE(line, socket) + if(line.size() == 0) { + // done with headers + break; + } + //Tiki::Debug::printf("HEADER_LINE: %s\n", line.c_str()); + if(line.find(":") != std::string::npos) { + std::string field = line.substr(0, line.find(":")); + std::string value = line.substr(line.find(":") + 1); + while(value.at(0) == ' ') { + value = value.substr(1); + } + + if(!field.compare("Set-Cookie")) { + + } + else { + response->setHeaderParam(field, value); + } + } + } + + RefPtr<Buffer> fullBuf = new Buffer(1); + + if(!response->getHeaderParam("Transfer-Encoding").compare("chunked")) { + Tiki::Debug::printf("Encoding is chunked\n"); + // evil chunked encoding + size_t totalSize = 0; + + size_t sizeDecoded = 0; + do + { + sizeDecoded = 0; + std::string size = ""; + READ_ONE_LINE(size, socket); + if(size.empty()) { + sizeDecoded = 1; + continue; + } + + std::istringstream sizestream(std::string("0x") + size); + sizestream.unsetf(std::ios::dec); + sizestream.setf(std::ios::skipws); + sizestream >> sizeDecoded; + + //Tiki::Debug::printf("chunk size: %d [%s]\n", sizeDecoded, size.c_str()); + if(sizeDecoded > 0) { + + RefPtr<Buffer> chunkBuf = new Buffer(sizeDecoded); + socket->recv(chunkBuf); + if(chunkBuf->getUsedDataLen() < sizeDecoded) + { + //Tiki::Debug::printf("Buffer underflow\n"); + size_t needed = sizeDecoded - chunkBuf->getUsedDataLen(); + while(needed > 0) { + RefPtr<Buffer> chunkBuf2 = new Buffer(needed); + socket->recv(chunkBuf2); + chunkBuf->append(chunkBuf2); + needed -= chunkBuf2->getUsedDataLen(); + } + } + totalSize += chunkBuf->getUsedDataLen(); + fullBuf->append(chunkBuf); + } + } while(sizeDecoded > 0); + //Tiki::Debug::printf("total size: %d %x\n", totalSize, totalSize); + } + else if(response->getHeaderParam("Content-Length").compare("")) { + Tiki::Debug::printf("Encoding is inline\n"); + size_t sizeDecoded = atoi(response->getHeaderParam("Content-Length").c_str()); + //Tiki::Debug::printf("decodedSize: %d\n", sizeDecoded); + + RefPtr<Buffer> chunkBuf = new Buffer(sizeDecoded); + socket->recv(chunkBuf); + if(chunkBuf->getUsedDataLen() < sizeDecoded) + { + sizeDecoded -= chunkBuf->getUsedDataLen(); + while(sizeDecoded > 0) { + RefPtr<Buffer> chunkBuf2 = new Buffer(sizeDecoded); + socket->recv(chunkBuf2); + chunkBuf->append(chunkBuf2); + sizeDecoded -= chunkBuf2->getUsedDataLen(); + } + } + fullBuf->append(chunkBuf); + } + else { + Tiki::Debug::printf("Encoding is unknown\n"); + } + response->addContentPart(fullBuf, DEFAULT_CONTENT_PART); +} + +}; // namespace Http + +}; // namespace Net + +}; // namespace Tiki + Modified: tiki/src/net/socket.cpp =================================================================== --- tiki/src/net/socket.cpp 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/src/net/socket.cpp 2007-08-23 22:59:57 UTC (rev 489) @@ -22,7 +22,7 @@ m_reuse = true; } -Socket::Socket(RefPtr<Address> address) +Socket::Socket(Address *address) { m_peerAddress = address; m_localAddress = new Address(); Modified: tiki/src/net/tcpserversocket.cpp =================================================================== --- tiki/src/net/tcpserversocket.cpp 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/src/net/tcpserversocket.cpp 2007-08-23 22:59:57 UTC (rev 489) @@ -50,7 +50,7 @@ } } -RefPtr<TCPSocket> TCPServerSocket::accept() +TCPSocket *TCPServerSocket::accept() { struct sockaddr_in sock_addr; #if TIKI_PLAT == TIKI_WIN32 Modified: tiki/src/net/tcpsocket.cpp =================================================================== --- tiki/src/net/tcpsocket.cpp 2007-08-23 18:35:40 UTC (rev 488) +++ tiki/src/net/tcpsocket.cpp 2007-08-23 22:59:57 UTC (rev 489) @@ -18,7 +18,7 @@ namespace TCP { -void TCPSocket::send(const RefPtr<Buffer> buffer) { +void TCPSocket::send(Buffer *buffer) { uint8 *data = buffer->getData(); size_t dataLen = buffer->getUsedDataLen(); int len; @@ -34,7 +34,7 @@ } while(dataLen > 0 && (len > 0 || errno == EINTR)); } -void TCPSocket::recv(RefPtr<Buffer> data) { +void TCPSocket::recv(Buffer *data) { uint8 *tmp = new uint8[data->getDataLen()]; memset(tmp, 0, data->getDataLen()); int recvlen = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-23 18:35:46
|
Revision: 488 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=488&view=rev Author: atani Date: 2007-08-23 11:35:40 -0700 (Thu, 23 Aug 2007) Log Message: ----------- update win32 project(s) to include Tiki::Net::Http code added Buffer.read(Tiki::File), Buffer.write(Tiki::File), Buffer(Tiki::File, ...) fixed chunked data size reading added Request.removeHeaderParam(std::string param) Added File.getFileName() Modified Paths: -------------- tiki/examples/net/httpclient/httpclient.vcproj tiki/include/Tiki/file.h tiki/include/Tiki/net/buffer.h tiki/include/Tiki/net/http/request.h tiki/src/base/file.cpp tiki/src/net/http/request.cpp tiki/src/net/http/response.cpp tiki/src/net/http/useragent.cpp tiki/src/net/tcpsocket.cpp tiki/win32/tiki_vc80.sln tiki/win32/tiki_vs80.vcproj Modified: tiki/examples/net/httpclient/httpclient.vcproj =================================================================== --- tiki/examples/net/httpclient/httpclient.vcproj 2007-08-23 00:01:53 UTC (rev 487) +++ tiki/examples/net/httpclient/httpclient.vcproj 2007-08-23 18:35:40 UTC (rev 488) @@ -191,7 +191,7 @@ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > <File - RelativePath=".\src\ChatClient.cpp" + RelativePath=".\src\HttpClient.cpp" > </File> <File Modified: tiki/include/Tiki/file.h =================================================================== --- tiki/include/Tiki/file.h 2007-08-23 00:01:53 UTC (rev 487) +++ tiki/include/Tiki/file.h 2007-08-23 18:35:40 UTC (rev 488) @@ -48,6 +48,8 @@ // Write cnt 32-bit little-endian words to the file. bool writele32( uint32 * in, int cnt ); + // Returns the filename associated with this File object. + string getFileName() const; // Seek in the file. int seek( int where, int whence ); @@ -79,6 +81,7 @@ }; RefPtr<FileFD> m_fd; + string m_fileName; }; } Modified: tiki/include/Tiki/net/buffer.h =================================================================== --- tiki/include/Tiki/net/buffer.h 2007-08-23 00:01:53 UTC (rev 487) +++ tiki/include/Tiki/net/buffer.h 2007-08-23 18:35:40 UTC (rev 488) @@ -9,6 +9,7 @@ #define __TIKI_NET_BUFFER_H #include "Tiki/object.h" +#include "Tiki/File.h" #include <fstream> @@ -16,6 +17,8 @@ namespace Net { +using Tiki::File; + class Buffer : public Object { public: @@ -34,7 +37,8 @@ memcpy(m_data, data, len); } - Buffer(std::string filename, std::string contentType, std::string fieldName = "") : m_fileName(filename), m_contentType(contentType), m_fieldName(fieldName) { + Buffer(std::string filename, std::string contentType, std::string fieldName = "") : + m_fileName(filename), m_contentType(contentType), m_fieldName(fieldName) { std::ifstream stream(filename.c_str(), std::ios::in | std::ios::binary); stream.seekg(0, std::ios::end); m_dataLen = m_usedDataLen = stream.tellg(); @@ -44,6 +48,24 @@ stream.close(); } + Buffer(Tiki::File file, std::string contentType, std::string fieldName = "") : + m_contentType(contentType), m_fieldName(fieldName) { + read(file); + } + + void read(Tiki::File file) { + assert(file.isValid()); + m_fileName = file.getFileName(); + m_dataLen = m_usedDataLen = file.total(); + m_data = new uint8[m_dataLen]; + file.read(m_data, m_dataLen); + } + + void write(Tiki::File file) { + assert(file.isValid()); + file.write(m_data, m_usedDataLen); + } + void append(RefPtr<Buffer> buf) { uint8 * newbuf = new uint8[ m_dataLen + buf->getDataLen() ]; memcpy(newbuf, m_data, m_usedDataLen); @@ -60,6 +82,7 @@ } uint8 *getData() const { + m_data[m_usedDataLen] = '\0'; return m_data; } Modified: tiki/include/Tiki/net/http/request.h =================================================================== --- tiki/include/Tiki/net/http/request.h 2007-08-23 00:01:53 UTC (rev 487) +++ tiki/include/Tiki/net/http/request.h 2007-08-23 18:35:40 UTC (rev 488) @@ -30,6 +30,7 @@ m_url = url; } + void removeHeaderParam(std::string param); void setHeaderParam(std::string param, std::string value); std::string getHeaderParam(std::string param) const; std::list<std::string> getHeaderParamNames() const; Modified: tiki/src/base/file.cpp =================================================================== --- tiki/src/base/file.cpp 2007-08-23 00:01:53 UTC (rev 487) +++ tiki/src/base/file.cpp 2007-08-23 18:35:40 UTC (rev 488) @@ -26,6 +26,7 @@ File::~File() {} bool File::open( const string & fn, const char * access ) { + m_fileName = fn; FILE * f = fopen( fn.c_str(), access ); if ( !f ) return false; @@ -132,6 +133,10 @@ #endif } +string File::getFileName() const { + return m_fileName; +} + int File::seek( int where, int whence ) { if ( !isValid() ) return -1; Modified: tiki/src/net/http/request.cpp =================================================================== --- tiki/src/net/http/request.cpp 2007-08-23 00:01:53 UTC (rev 487) +++ tiki/src/net/http/request.cpp 2007-08-23 18:35:40 UTC (rev 488) @@ -6,6 +6,7 @@ Copyright (C)2007 Atani Software */ +#include "pch.h" #include "Tiki/tiki.h" #include "Tiki/net.h" #include "Tiki/net/http/request.h" @@ -24,11 +25,17 @@ } +void Request::removeHeaderParam(std::string param) { + if(m_params.find(param) != m_params.end()) { + m_params.erase(m_params.find(param)); + } +} + void Request::setHeaderParam(std::string param, std::string value) { -// if(m_params.find(param) != m_params.end()) { -// m_params.erase(m_params.find(param)); -// } - + if(!param.compare("User-Agent")) { + Tiki::Debug::printf("Setting User-Agent via Request::setHeaderParam() is not allowed. Use HttpUserAgent::setUserAgentName() instead.\n"); + return; + } m_params.insert(std::make_pair(param, value)); } Modified: tiki/src/net/http/response.cpp =================================================================== --- tiki/src/net/http/response.cpp 2007-08-23 00:01:53 UTC (rev 487) +++ tiki/src/net/http/response.cpp 2007-08-23 18:35:40 UTC (rev 488) @@ -6,6 +6,7 @@ Copyright (C)2007 Atani Software */ +#include "pch.h" #include "Tiki/tiki.h" #include "Tiki/net.h" #include "Tiki/net/http/request.h" Modified: tiki/src/net/http/useragent.cpp =================================================================== --- tiki/src/net/http/useragent.cpp 2007-08-23 00:01:53 UTC (rev 487) +++ tiki/src/net/http/useragent.cpp 2007-08-23 18:35:40 UTC (rev 488) @@ -6,6 +6,7 @@ Copyright (C)2007 Atani Software */ +#include "pch.h" #include "Tiki/tiki.h" #include "Tiki/net.h" #include "Tiki/net/http/useragent.h" @@ -43,7 +44,17 @@ } HttpUserAgent::HttpUserAgent() { - setUserAgentName("Tiki/1.0"); +#if TIKI_PLAT == TIKI_WIN32 + setUserAgentName("Tiki/1.0 (Windows)"); +#elif TIKI_PLAT == TIKI_NDS + setUserAgentName("Tiki/1.0 (Nintendo DS)"); +#elif TIKI_PLAT == TIKI_SDL + setUserAgentName("Tiki/1.0 (SDL)"); +#elif TIKI_PLAT == TIKI_OSX + setUserAgentName("Tiki/1.0 (Mac OS X)"); +#else + setUserAgentName("Tiki/1.0 (Unknown)"); +#endif setProxyHost(""); setProxyPort(8080); } @@ -79,7 +90,7 @@ } RefPtr<Buffer> buf = new Buffer(2048); - buf->setData((uint8 *)requestText.c_str(), requestText.size()); + buf->setData((uint8 *)requestText.c_str(), requestText.length()); socket->send(buf); readResponse(response, socket); @@ -118,7 +129,7 @@ } RefPtr<Buffer> buf = new Buffer(2048); - buf->setData((uint8 *)requestText.c_str(), requestText.size()); + buf->setData((uint8 *)requestText.c_str(), requestText.length()); socket->send(buf); std::list<std::string> content = req->getContentPartNames(); @@ -130,7 +141,7 @@ std::stringstream temp; temp << req->getBoundaryMarker() << "\r\n"; temp << "Content-Disposition: form-data: name=\""; - if(buf->getFieldName().size() > 0) { + if(!buf->getFieldName().empty()) { temp << buf->getFieldName(); } else { @@ -139,7 +150,7 @@ temp << "\"; filename=\"" << buf->getFileNameShort() << "\"\r\nContent-Type: " << buf->getContentType() << "\r\n"; RefPtr<Buffer> headerBuf = new Buffer(2048); std::string headerText = temp.str(); - headerBuf->setData((uint8 *)headerText.c_str(), headerText.size()); + headerBuf->setData((uint8 *)headerText.c_str(), headerText.length()); socket->send(headerBuf); socket->send(buf); } @@ -147,7 +158,7 @@ footerText.append(req->getBoundaryMarker()); footerText.append("--\r\n"); RefPtr<Buffer> footerBuf = new Buffer(2048); - footerBuf->setData((uint8 *)footerText.c_str(), footerText.size()); + footerBuf->setData((uint8 *)footerText.c_str(), footerText.length()); socket->send(footerBuf); } else if(content.size() == 1) { @@ -214,9 +225,13 @@ req << *param << ": " << request->getHeaderParam(*param) << "\r\n"; } + if(!m_userAgentName.empty()) { + req << "User-Agent: " << m_userAgentName << "\r\n"; + } + std::list<std::string> content = request->getContentPartNames(); if(!mode.compare("POST") && content.size() > 1) { - uint64 totalSize = request->getBoundaryMarker().size() + 6; // add 6 to account for "--<boundary>--\r\n" + uint64 totalSize = request->getBoundaryMarker().length() + 6; // add 6 to account for "--<boundary>--\r\n" for(std::list<std::string>::iterator iter = content.begin(); iter != content.end(); ++iter) { @@ -224,7 +239,7 @@ totalSize += buf->getUsedDataLen(); std::stringstream temp; temp << "Content-Disposition: form-data: name=\""; - if(buf->getFieldName().size() > 0) { + if(!buf->getFieldName().empty()) { temp << buf->getFieldName(); } else { @@ -233,7 +248,7 @@ temp << "\"; filename=\"" << buf->getFileNameShort() << "\"\r\nContent-Type: " << buf->getContentType() << "\r\n"; // add section header size - totalSize += temp.str().size(); + totalSize += temp.str().length(); } req << "Content-Length: " << totalSize << "\r\n"; @@ -247,7 +262,6 @@ } req << "\r\n"; - Tiki::Debug::printf("Request Text: %s\n", req.str().c_str()); requestText = req.str(); } @@ -255,8 +269,8 @@ std::string status = ""; READ_ONE_LINE(status, socket) - Tiki::Debug::printf("Status: %s\n", status.c_str()); - for(int i = 0; i < status.size(); i++) { + //Tiki::Debug::printf("Status: %s\n", status.c_str()); + for(int i = 0; i < status.length(); i++) { if(status.at(i) == ' ') { response->setResultCode(atoi(status.c_str()+i + 1)); break; @@ -270,6 +284,7 @@ // done with headers break; } + //Tiki::Debug::printf("HEADER_LINE: %s\n", line.c_str()); if(line.find(":") != std::string::npos) { std::string field = line.substr(0, line.find(":")); std::string value = line.substr(line.find(":") + 1); @@ -299,13 +314,17 @@ sizeDecoded = 0; std::string size = ""; READ_ONE_LINE(size, socket); - if(size.size() == 0) { + if(size.empty()) { sizeDecoded = 1; continue; } + while(size.find(" ") != std::string::npos) { + size.erase(size.find(" "), 1); + } + int base = 1; - for(int i = 0; i < size.size(); i++ ) { + for(int i = 0; i < size.length(); i++ ) { char ch = size.at(i); if(ch >= 'A' && ch <= 'F') { ch -= 'A'; @@ -321,7 +340,7 @@ else { continue; } - sizeDecoded += (ch * static_cast<int>(pow(16.0f, size.size() - i - 1))); + sizeDecoded += (ch * static_cast<int>(pow(16.0f, static_cast<int>(size.length() - i - 1)))); } //Tiki::Debug::printf("chunk size: %d [%s]\n", sizeDecoded, size.c_str()); if(sizeDecoded > 0) { @@ -343,12 +362,12 @@ fullBuf->append(chunkBuf); } } while(sizeDecoded > 0); - Tiki::Debug::printf("total size: %d %x\n", totalSize, totalSize); + //Tiki::Debug::printf("total size: %d %x\n", totalSize, totalSize); } else if(response->getHeaderParam("Content-Length").compare("")) { Tiki::Debug::printf("Encoding is inline\n"); long sizeDecoded = atoi(response->getHeaderParam("Content-Length").c_str()); - Tiki::Debug::printf("decodedSize: %d\n", sizeDecoded); + //Tiki::Debug::printf("decodedSize: %d\n", sizeDecoded); RefPtr<Buffer> chunkBuf = new Buffer(sizeDecoded); socket->recv(chunkBuf); Modified: tiki/src/net/tcpsocket.cpp =================================================================== --- tiki/src/net/tcpsocket.cpp 2007-08-23 00:01:53 UTC (rev 487) +++ tiki/src/net/tcpsocket.cpp 2007-08-23 18:35:40 UTC (rev 488) @@ -105,9 +105,9 @@ void TCPSocket::close() { m_open = false; Tiki::Debug::printf("closing socket\n"); - if(m_socket != INVALID_SOCKET) { + if(m_socket != INVALID_SOCKET) { #if TIKI_PLAT == TIKI_WIN32 - shutdown(m_socket, SHUT_RDWR); + ::shutdown(m_socket, SD_BOTH); closesocket(m_socket); #else ::shutdown(m_socket, SHUT_RDWR); Modified: tiki/win32/tiki_vc80.sln =================================================================== --- tiki/win32/tiki_vc80.sln 2007-08-23 00:01:53 UTC (rev 487) +++ tiki/win32/tiki_vc80.sln 2007-08-23 18:35:40 UTC (rev 488) @@ -28,6 +28,11 @@ {F2816CAC-B560-4ED9-8A73-9635F832943C} = {F2816CAC-B560-4ED9-8A73-9635F832943C} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HttpClient", "..\examples\net\httpclient\httpclient.vcproj", "{7B823C96-861C-4578-95FF-1087A45AF1AA}" + ProjectSection(ProjectDependencies) = postProject + {F2816CAC-B560-4ED9-8A73-9635F832943C} = {F2816CAC-B560-4ED9-8A73-9635F832943C} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -58,6 +63,10 @@ {7B823C96-860C-4578-95EE-1087A45AF1AA}.Debug|Win32.Build.0 = Debug|Win32 {7B823C96-860C-4578-95EE-1087A45AF1AA}.Release|Win32.ActiveCfg = Release|Win32 {7B823C96-860C-4578-95EE-1087A45AF1AA}.Release|Win32.Build.0 = Release|Win32 + {7B823C96-861C-4578-95FF-1087A45AF1AA}.Debug|Win32.ActiveCfg = Debug|Win32 + {7B823C96-861C-4578-95FF-1087A45AF1AA}.Debug|Win32.Build.0 = Debug|Win32 + {7B823C96-861C-4578-95FF-1087A45AF1AA}.Release|Win32.ActiveCfg = Release|Win32 + {7B823C96-861C-4578-95FF-1087A45AF1AA}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE Modified: tiki/win32/tiki_vs80.vcproj =================================================================== --- tiki/win32/tiki_vs80.vcproj 2007-08-23 00:01:53 UTC (rev 487) +++ tiki/win32/tiki_vs80.vcproj 2007-08-23 18:35:40 UTC (rev 488) @@ -415,6 +415,22 @@ RelativePath="..\src\net\tcpsocket.cpp" > </File> + <Filter + Name="http" + > + <File + RelativePath="..\src\net\http\request.cpp" + > + </File> + <File + RelativePath="..\src\net\http\response.cpp" + > + </File> + <File + RelativePath="..\src\net\http\useragent.cpp" + > + </File> + </Filter> </Filter> </Filter> <Filter @@ -675,6 +691,26 @@ RelativePath="..\include\Tiki\net\udpsocket.h" > </File> + <Filter + Name="http" + > + <File + RelativePath="..\include\Tiki\net\http\cookie.h" + > + </File> + <File + RelativePath="..\include\Tiki\net\http\request.h" + > + </File> + <File + RelativePath="..\include\Tiki\net\http\response.h" + > + </File> + <File + RelativePath="..\include\Tiki\net\http\useragent.h" + > + </File> + </Filter> </Filter> </Filter> </Filter> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-23 00:02:00
|
Revision: 487 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=487&view=rev Author: atani Date: 2007-08-22 17:01:53 -0700 (Wed, 22 Aug 2007) Log Message: ----------- nds and osx Tiki::Net support Modified Paths: -------------- tiki/include/Tiki/net/tcpsocket.h tiki/include/Tiki/net.h tiki/nds/Makefile tiki/osx/Tiki.xcodeproj/project.pbxproj tiki/osx/src/init_shutdown.cpp tiki/osx/src/platnet.cpp tiki/sdl/src/platnet.cpp tiki/src/net/address.cpp tiki/src/net/tcpserversocket.cpp tiki/src/net/tcpsocket.cpp Added Paths: ----------- tiki/nds/include/Tiki/platnet.h tiki/nds/src/platnet.cpp Modified: tiki/include/Tiki/net/tcpsocket.h =================================================================== --- tiki/include/Tiki/net/tcpsocket.h 2007-08-22 20:47:44 UTC (rev 486) +++ tiki/include/Tiki/net/tcpsocket.h 2007-08-23 00:01:53 UTC (rev 487) @@ -25,11 +25,12 @@ public: #ifndef INVALID_SOCKET - enum { - INVALID_SOCKET = -1, - SOCKET_ERROR = -1 - }; +#define INVALID_SOCKET -1 #endif + +#ifndef SOCKET_ERROR +#define SOCKET_ERROR -1 +#endif TCPSocket() : Socket(), m_open(false) {}; TCPSocket(RefPtr<Address> address) : Socket(address), m_open(false) {}; #if TIKI_PLAT == TIKI_WIN32 Modified: tiki/include/Tiki/net.h =================================================================== --- tiki/include/Tiki/net.h 2007-08-22 20:47:44 UTC (rev 486) +++ tiki/include/Tiki/net.h 2007-08-23 00:01:53 UTC (rev 487) @@ -14,6 +14,9 @@ void init(); void shutdown(); +bool connect(); +bool isConnected(); +void disconnect(); } // namespace Net Modified: tiki/nds/Makefile =================================================================== --- tiki/nds/Makefile 2007-08-22 20:47:44 UTC (rev 486) +++ tiki/nds/Makefile 2007-08-23 00:01:53 UTC (rev 487) @@ -10,6 +10,8 @@ BASE_IMAGE_OBJ=$(patsubst %.cpp,%.o,$(wildcard ../src/image/*.cpp)) BASE_MATH_OBJ=$(patsubst %.cpp,%.o,$(wildcard ../src/math/*.cpp)) BASE_THREAD_OBJ=$(patsubst %.cpp,%.o,$(wildcard ../src/thread/*.cpp)) +BASE_NET_OBJ=$(patsubst %.cpp,%.o,$(wildcard ../src/net/*.cpp)) +BASE_NET_OBJ+=$(patsubst %.cpp,%.o,$(wildcard ../src/net/http/*.cpp)) JPEG_OBJ=$(patsubst %.c,%.o,$(wildcard ../3rdparty/libjpeg/*.c)) PNG_OBJ=$(patsubst %.c,%.o,$(wildcard ../3rdparty/libpng/*.c)) @@ -39,7 +41,7 @@ BASE_OBJS = $(BASE_AUDIO_OBJ) $(BASE_BASE_OBJ) $(BASE_GL_OBJ) \ $(BASE_HID_OBJ) $(BASE_IMAGE_OBJ) $(BASE_MATH_OBJ) \ - $(BASE_THREAD_OBJ) + $(BASE_THREAD_OBJ) $(BASE_NET_OBJ) THIRD_PARTY_OBJS = $(JPEG_OBJ) $(OGG_OBJ) $(VORBIS_OBJ) $(PNG_OBJ) $(ZLIB_OBJ) @@ -56,6 +58,10 @@ examples: $(MAKE) TIKI_PLAT=nds TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/TikiTest $(MAKE) TIKI_PLAT=nds TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/console/TikiSnake + $(MAKE) TIKI_PLAT=nds TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/net/basic + $(MAKE) TIKI_PLAT=nds TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/net/chat + $(MAKE) TIKI_PLAT=nds TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/net/chatd + $(MAKE) TIKI_PLAT=nds TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/net/httpclient package: zip -9r ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-nds.zip \ Added: tiki/nds/include/Tiki/platnet.h =================================================================== --- tiki/nds/include/Tiki/platnet.h (rev 0) +++ tiki/nds/include/Tiki/platnet.h 2007-08-23 00:01:53 UTC (rev 487) @@ -0,0 +1,14 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <netinet/in.h> +#include <netdb.h> +#include <sys/socket.h> +#include <sys/time.h> + +#include <nds.h> +#include <dswifi9.h> + Added: tiki/nds/src/platnet.cpp =================================================================== --- tiki/nds/src/platnet.cpp (rev 0) +++ tiki/nds/src/platnet.cpp 2007-08-23 00:01:53 UTC (rev 487) @@ -0,0 +1,50 @@ +/* + Tiki + + platnet.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "Tiki/tiki.h" +#include "Tiki/net.h" + +namespace Tiki { + +namespace Net { + +void init() { +} + +void shutdown() { +} + +bool connect() { + if(!isConnected()) { + Wifi_AutoConnect(); + while(1) { + switch(Wifi_AssocStatus()) { + case ASSOCSTATUS_ASSOCIATED: + return true; + case ASSOCSTATUS_CANNOTCONNECT: + return false; + } + } + } + + return true; +} + +bool isConnected() { + return (Wifi_AssocStatus() == ASSOCSTATUS_ASSOCIATED); +} + +void disconnect() { + if(isConnected()) { + Wifi_DisconnectAP(); + } +} + +} // namespace Net + +} // namespace Tiki Modified: tiki/osx/Tiki.xcodeproj/project.pbxproj =================================================================== --- tiki/osx/Tiki.xcodeproj/project.pbxproj 2007-08-22 20:47:44 UTC (rev 486) +++ tiki/osx/Tiki.xcodeproj/project.pbxproj 2007-08-23 00:01:53 UTC (rev 487) @@ -17,6 +17,27 @@ 6444BEE60932A3D800A29768 /* texturetile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6444BEE50932A3D700A29768 /* texturetile.cpp */; }; 6444BEE80932A3F200A29768 /* texturetile.h in Headers */ = {isa = PBXBuildFile; fileRef = 6444BEE70932A3F200A29768 /* texturetile.h */; }; 64D758F4092EB9A5002667EE /* sleep.h in Headers */ = {isa = PBXBuildFile; fileRef = 64D758F3092EB9A5002667EE /* sleep.h */; }; + 64ED75F50C7CFAE500D16D5C /* address.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 64ED75F10C7CFAE500D16D5C /* address.cpp */; }; + 64ED75F60C7CFAE500D16D5C /* socket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 64ED75F20C7CFAE500D16D5C /* socket.cpp */; }; + 64ED75F70C7CFAE500D16D5C /* tcpserversocket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 64ED75F30C7CFAE500D16D5C /* tcpserversocket.cpp */; }; + 64ED75F80C7CFAE500D16D5C /* tcpsocket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 64ED75F40C7CFAE500D16D5C /* tcpsocket.cpp */; }; + 64ED75FD0C7CFB1800D16D5C /* request.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 64ED75FA0C7CFB1800D16D5C /* request.cpp */; }; + 64ED75FE0C7CFB1800D16D5C /* response.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 64ED75FB0C7CFB1800D16D5C /* response.cpp */; }; + 64ED75FF0C7CFB1800D16D5C /* useragent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 64ED75FC0C7CFB1800D16D5C /* useragent.cpp */; }; + 64ED76190C7CFB4C00D16D5C /* address.h in Headers */ = {isa = PBXBuildFile; fileRef = 64ED76130C7CFB4C00D16D5C /* address.h */; }; + 64ED761A0C7CFB4C00D16D5C /* buffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 64ED76140C7CFB4C00D16D5C /* buffer.h */; }; + 64ED761B0C7CFB4C00D16D5C /* socket.h in Headers */ = {isa = PBXBuildFile; fileRef = 64ED76150C7CFB4C00D16D5C /* socket.h */; }; + 64ED761C0C7CFB4C00D16D5C /* tcpserversocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 64ED76160C7CFB4C00D16D5C /* tcpserversocket.h */; }; + 64ED761D0C7CFB4C00D16D5C /* tcpsocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 64ED76170C7CFB4C00D16D5C /* tcpsocket.h */; }; + 64ED761E0C7CFB4C00D16D5C /* udpsocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 64ED76180C7CFB4C00D16D5C /* udpsocket.h */; }; + 64ED76230C7CFB6200D16D5C /* cookie.h in Headers */ = {isa = PBXBuildFile; fileRef = 64ED761F0C7CFB6200D16D5C /* cookie.h */; }; + 64ED76240C7CFB6200D16D5C /* request.h in Headers */ = {isa = PBXBuildFile; fileRef = 64ED76200C7CFB6200D16D5C /* request.h */; }; + 64ED76250C7CFB6200D16D5C /* response.h in Headers */ = {isa = PBXBuildFile; fileRef = 64ED76210C7CFB6200D16D5C /* response.h */; }; + 64ED76260C7CFB6200D16D5C /* useragent.h in Headers */ = {isa = PBXBuildFile; fileRef = 64ED76220C7CFB6200D16D5C /* useragent.h */; }; + 64ED76290C7CFB7E00D16D5C /* endian.h in Headers */ = {isa = PBXBuildFile; fileRef = 64ED76270C7CFB7E00D16D5C /* endian.h */; }; + 64ED762A0C7CFB7E00D16D5C /* net.h in Headers */ = {isa = PBXBuildFile; fileRef = 64ED76280C7CFB7E00D16D5C /* net.h */; }; + 64ED762C0C7CFB9400D16D5C /* platnet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 64ED762B0C7CFB9400D16D5C /* platnet.cpp */; }; + 64ED762E0C7CFBA100D16D5C /* platnet.h in Headers */ = {isa = PBXBuildFile; fileRef = 64ED762D0C7CFBA100D16D5C /* platnet.h */; }; 8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; }; 8DC2EF570486A6940098B216 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */; }; C4287F7C07C9491100D238E1 /* image.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C4287F7B07C9491100D238E1 /* image.cpp */; }; @@ -184,6 +205,27 @@ 6444BEE50932A3D700A29768 /* texturetile.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = texturetile.cpp; path = ../src/gl/drawables/texturetile.cpp; sourceTree = SOURCE_ROOT; }; 6444BEE70932A3F200A29768 /* texturetile.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = texturetile.h; path = ../include/Tiki/drawables/texturetile.h; sourceTree = SOURCE_ROOT; }; 64D758F3092EB9A5002667EE /* sleep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sleep.h; path = ../include/Tiki/anims/sleep.h; sourceTree = SOURCE_ROOT; }; + 64ED75F10C7CFAE500D16D5C /* address.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = address.cpp; path = ../src/net/address.cpp; sourceTree = SOURCE_ROOT; }; + 64ED75F20C7CFAE500D16D5C /* socket.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = socket.cpp; path = ../src/net/socket.cpp; sourceTree = SOURCE_ROOT; }; + 64ED75F30C7CFAE500D16D5C /* tcpserversocket.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = tcpserversocket.cpp; path = ../src/net/tcpserversocket.cpp; sourceTree = SOURCE_ROOT; }; + 64ED75F40C7CFAE500D16D5C /* tcpsocket.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = tcpsocket.cpp; path = ../src/net/tcpsocket.cpp; sourceTree = SOURCE_ROOT; }; + 64ED75FA0C7CFB1800D16D5C /* request.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = request.cpp; path = ../src/net/http/request.cpp; sourceTree = SOURCE_ROOT; }; + 64ED75FB0C7CFB1800D16D5C /* response.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = response.cpp; path = ../src/net/http/response.cpp; sourceTree = SOURCE_ROOT; }; + 64ED75FC0C7CFB1800D16D5C /* useragent.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = useragent.cpp; path = ../src/net/http/useragent.cpp; sourceTree = SOURCE_ROOT; }; + 64ED76130C7CFB4C00D16D5C /* address.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = address.h; path = ../include/Tiki/net/address.h; sourceTree = SOURCE_ROOT; }; + 64ED76140C7CFB4C00D16D5C /* buffer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = buffer.h; path = ../include/Tiki/net/buffer.h; sourceTree = SOURCE_ROOT; }; + 64ED76150C7CFB4C00D16D5C /* socket.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = socket.h; path = ../include/Tiki/net/socket.h; sourceTree = SOURCE_ROOT; }; + 64ED76160C7CFB4C00D16D5C /* tcpserversocket.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = tcpserversocket.h; path = ../include/Tiki/net/tcpserversocket.h; sourceTree = SOURCE_ROOT; }; + 64ED76170C7CFB4C00D16D5C /* tcpsocket.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = tcpsocket.h; path = ../include/Tiki/net/tcpsocket.h; sourceTree = SOURCE_ROOT; }; + 64ED76180C7CFB4C00D16D5C /* udpsocket.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = udpsocket.h; path = ../include/Tiki/net/udpsocket.h; sourceTree = SOURCE_ROOT; }; + 64ED761F0C7CFB6200D16D5C /* cookie.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = cookie.h; path = ../include/Tiki/net/http/cookie.h; sourceTree = SOURCE_ROOT; }; + 64ED76200C7CFB6200D16D5C /* request.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = request.h; path = ../include/Tiki/net/http/request.h; sourceTree = SOURCE_ROOT; }; + 64ED76210C7CFB6200D16D5C /* response.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = response.h; path = ../include/Tiki/net/http/response.h; sourceTree = SOURCE_ROOT; }; + 64ED76220C7CFB6200D16D5C /* useragent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = useragent.h; path = ../include/Tiki/net/http/useragent.h; sourceTree = SOURCE_ROOT; }; + 64ED76270C7CFB7E00D16D5C /* endian.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = endian.h; path = ../include/Tiki/endian.h; sourceTree = SOURCE_ROOT; }; + 64ED76280C7CFB7E00D16D5C /* net.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = net.h; path = ../include/Tiki/net.h; sourceTree = SOURCE_ROOT; }; + 64ED762B0C7CFB9400D16D5C /* platnet.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = platnet.cpp; path = src/platnet.cpp; sourceTree = "<group>"; }; + 64ED762D0C7CFBA100D16D5C /* platnet.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = platnet.h; path = include/Tiki/platnet.h; sourceTree = "<group>"; }; 8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; }; 8DC2EF5B0486A6940098B216 /* Tiki.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Tiki.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C40D72C1083723B50084B52D /* design_v2.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = design_v2.rtf; path = ../notes/design_v2.rtf; sourceTree = SOURCE_ROOT; }; @@ -475,9 +517,57 @@ name = "Other Sources"; sourceTree = "<group>"; }; + 64ED75F00C7CFAC500D16D5C /* net */ = { + isa = PBXGroup; + children = ( + 64ED75F90C7CFAE900D16D5C /* http */, + 64ED75F10C7CFAE500D16D5C /* address.cpp */, + 64ED75F20C7CFAE500D16D5C /* socket.cpp */, + 64ED75F30C7CFAE500D16D5C /* tcpserversocket.cpp */, + 64ED75F40C7CFAE500D16D5C /* tcpsocket.cpp */, + ); + name = net; + sourceTree = "<group>"; + }; + 64ED75F90C7CFAE900D16D5C /* http */ = { + isa = PBXGroup; + children = ( + 64ED75FA0C7CFB1800D16D5C /* request.cpp */, + 64ED75FB0C7CFB1800D16D5C /* response.cpp */, + 64ED75FC0C7CFB1800D16D5C /* useragent.cpp */, + ); + name = http; + sourceTree = "<group>"; + }; + 64ED76110C7CFB2200D16D5C /* net */ = { + isa = PBXGroup; + children = ( + 64ED76130C7CFB4C00D16D5C /* address.h */, + 64ED76140C7CFB4C00D16D5C /* buffer.h */, + 64ED76150C7CFB4C00D16D5C /* socket.h */, + 64ED76160C7CFB4C00D16D5C /* tcpserversocket.h */, + 64ED76170C7CFB4C00D16D5C /* tcpsocket.h */, + 64ED76180C7CFB4C00D16D5C /* udpsocket.h */, + 64ED76120C7CFB2D00D16D5C /* http */, + ); + name = net; + sourceTree = "<group>"; + }; + 64ED76120C7CFB2D00D16D5C /* http */ = { + isa = PBXGroup; + children = ( + 64ED761F0C7CFB6200D16D5C /* cookie.h */, + 64ED76200C7CFB6200D16D5C /* request.h */, + 64ED76210C7CFB6200D16D5C /* response.h */, + 64ED76220C7CFB6200D16D5C /* useragent.h */, + ); + name = http; + sourceTree = "<group>"; + }; C42BD273078FC90300061670 /* Include */ = { isa = PBXGroup; children = ( + 64ED76110C7CFB2200D16D5C /* net */, C4AD531B0793CF3400E1B779 /* AutoIncluded */, C48ACAD2079B7121005DF20E /* audio */, C4AD50FD0793ABEC00E1B779 /* base */, @@ -492,10 +582,11 @@ C42BD2AD078FC94800061670 /* Source */ = { isa = PBXGroup; children = ( + 64ED75F00C7CFAC500D16D5C /* net */, C4AD52E30793CDC100E1B779 /* audio */, C42BD2D6078FC9BF00061670 /* base */, C4F51516079A0B1C0001D0D0 /* gl */, - C4539923079A455600F3A584 /* hid */, + C4539923079A455600F3A584 /* t */, C48814FE079F8A3B0038D5B0 /* image */, C4F5157D079A0CFB0001D0D0 /* math */, C472B72C079B0FBA00F0C00A /* thread */, @@ -538,6 +629,7 @@ C42BD4B0078FCB0A00061670 /* Source */ = { isa = PBXGroup; children = ( + 64ED762B0C7CFB9400D16D5C /* platnet.cpp */, C498925907EE98040050854A /* platgl.cpp */, C498925707EE97E70050854A /* TikiMain.m */, C4B5838C0794CFC7004D22F2 /* init_shutdown.cpp */, @@ -551,6 +643,7 @@ C42BD4B1078FCB0E00061670 /* Include */ = { isa = PBXGroup; children = ( + 64ED762D0C7CFBA100D16D5C /* platnet.h */, C4AD527D0793C96A00E1B779 /* glhdrs.h */, C42BD4B3078FCB5A00061670 /* pch.h */, C472B719079AFA1600F0C00A /* platthread.h */, @@ -579,13 +672,13 @@ name = hid; sourceTree = "<group>"; }; - C4539923079A455600F3A584 /* hid */ = { + C4539923079A455600F3A584 /* t */ = { isa = PBXGroup; children = ( C48E6CD607A48FDE00045273 /* eventcollector.cpp */, C453992A079A477500F3A584 /* hid.cpp */, ); - name = hid; + name = t; sourceTree = "<group>"; }; C472B72C079B0FBA00F0C00A /* thread */ = { @@ -629,6 +722,8 @@ C4AD50FD0793ABEC00E1B779 /* base */ = { isa = PBXGroup; children = ( + 64ED76270C7CFB7E00D16D5C /* endian.h */, + 64ED76280C7CFB7E00D16D5C /* net.h */, C4EAEB1F08678F1F003F5342 /* TikiAll.h */, C4AD50E30793ABA000E1B779 /* debug.h */, C4AD522B0793B4E300E1B779 /* file.h */, @@ -979,6 +1074,19 @@ 2290A10209302D9F00B7D80C /* pointerArrow.h in Headers */, 6444BEE80932A3F200A29768 /* texturetile.h in Headers */, 223226830A165A7A0035025E /* console.h in Headers */, + 64ED76190C7CFB4C00D16D5C /* address.h in Headers */, + 64ED761A0C7CFB4C00D16D5C /* buffer.h in Headers */, + 64ED761B0C7CFB4C00D16D5C /* socket.h in Headers */, + 64ED761C0C7CFB4C00D16D5C /* tcpserversocket.h in Headers */, + 64ED761D0C7CFB4C00D16D5C /* tcpsocket.h in Headers */, + 64ED761E0C7CFB4C00D16D5C /* udpsocket.h in Headers */, + 64ED76230C7CFB6200D16D5C /* cookie.h in Headers */, + 64ED76240C7CFB6200D16D5C /* request.h in Headers */, + 64ED76250C7CFB6200D16D5C /* response.h in Headers */, + 64ED76260C7CFB6200D16D5C /* useragent.h in Headers */, + 64ED76290C7CFB7E00D16D5C /* endian.h in Headers */, + 64ED762A0C7CFB7E00D16D5C /* net.h in Headers */, + 64ED762E0C7CFBA100D16D5C /* platnet.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1186,6 +1294,14 @@ 2290A0FE09302D7500B7D80C /* pointerArrow.cpp in Sources */, 6444BEE60932A3D800A29768 /* texturetile.cpp in Sources */, 223226810A165A600035025E /* console.cpp in Sources */, + 64ED75F50C7CFAE500D16D5C /* address.cpp in Sources */, + 64ED75F60C7CFAE500D16D5C /* socket.cpp in Sources */, + 64ED75F70C7CFAE500D16D5C /* tcpserversocket.cpp in Sources */, + 64ED75F80C7CFAE500D16D5C /* tcpsocket.cpp in Sources */, + 64ED75FD0C7CFB1800D16D5C /* request.cpp in Sources */, + 64ED75FE0C7CFB1800D16D5C /* response.cpp in Sources */, + 64ED75FF0C7CFB1800D16D5C /* useragent.cpp in Sources */, + 64ED762C0C7CFB9400D16D5C /* platnet.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; Modified: tiki/osx/src/init_shutdown.cpp =================================================================== --- tiki/osx/src/init_shutdown.cpp 2007-08-22 20:47:44 UTC (rev 486) +++ tiki/osx/src/init_shutdown.cpp 2007-08-23 00:01:53 UTC (rev 487) @@ -34,7 +34,7 @@ #if defined(ALC_VERSION_0_1) dev = alcOpenDevice( const_cast<ALCchar *>( getenv( "OPENAL_DEVICE" ) ) ); // getenv()==NULL is okay. #else - dev = alcOpenDevice( getenv( "OPENAL_DEVICE" ) ); // getenv()==NULL is okay. + dev = alcOpenDevice( (ALCuint8 *)( getenv( "OPENAL_DEVICE" ) ) ); // getenv()==NULL is okay. #endif if ( dev != NULL ) { Modified: tiki/osx/src/platnet.cpp =================================================================== --- tiki/osx/src/platnet.cpp 2007-08-22 20:47:44 UTC (rev 486) +++ tiki/osx/src/platnet.cpp 2007-08-23 00:01:53 UTC (rev 487) @@ -7,7 +7,7 @@ */ #include "Tiki/tiki.h" -#include "Tiki/net/net.h" +#include "Tiki/net.h" namespace Tiki { @@ -19,6 +19,17 @@ void shutdown() { } +bool connect() { + return true; +} + +bool isConnect() { + return true; +} + +void disconnect() { +} + }; // namespace Net }; // namespace Tiki Modified: tiki/sdl/src/platnet.cpp =================================================================== --- tiki/sdl/src/platnet.cpp 2007-08-22 20:47:44 UTC (rev 486) +++ tiki/sdl/src/platnet.cpp 2007-08-23 00:01:53 UTC (rev 487) @@ -13,14 +13,18 @@ namespace Net { -void init() -{ +void init() { } -void shutdown() -{ +void shutdown() { } +bool connect() { +} + +void disconnect() { +} + } // namespace Net } // namespace Tiki Modified: tiki/src/net/address.cpp =================================================================== --- tiki/src/net/address.cpp 2007-08-22 20:47:44 UTC (rev 486) +++ tiki/src/net/address.cpp 2007-08-23 00:01:53 UTC (rev 487) @@ -25,6 +25,7 @@ string Address::getHostName() { +#if TIKI_PLAT != TIKI_NDS if(m_hostname.empty() && m_ip != AddressUnknown && m_ip != AddressBroadcast && @@ -37,6 +38,7 @@ m_hostname = string(hp->h_name); } } +#endif return m_hostname; } @@ -55,7 +57,11 @@ struct hostent *hp = gethostbyname(m_hostname.c_str()); if(hp != NULL) { +#if TIKI_PLAT == TIKI_NDS + memcpy(&m_ip, hp->h_addr_list[0], sizeof(unsigned long)); +#else memcpy(&m_ip, hp->h_addr, hp->h_length); +#endif } } return m_ip; Modified: tiki/src/net/tcpserversocket.cpp =================================================================== --- tiki/src/net/tcpserversocket.cpp 2007-08-22 20:47:44 UTC (rev 486) +++ tiki/src/net/tcpserversocket.cpp 2007-08-23 00:01:53 UTC (rev 487) @@ -60,7 +60,7 @@ #endif size_t addrlen = sizeof(struct sockaddr_in); -#if TIKI_PLAT == TIKI_SDL +#if TIKI_PLAT == TIKI_SDL || TIKI_PLAT == TIKI_OSX socket = ::accept(m_socket, (sockaddr *)&sock_addr, (socklen_t *)&addrlen); #else socket = ::accept(m_socket, (sockaddr *)&sock_addr, (int *)&addrlen); Modified: tiki/src/net/tcpsocket.cpp =================================================================== --- tiki/src/net/tcpsocket.cpp 2007-08-22 20:47:44 UTC (rev 486) +++ tiki/src/net/tcpsocket.cpp 2007-08-23 00:01:53 UTC (rev 487) @@ -70,10 +70,12 @@ int yes = 1; +#if TIKI_PLAT != TIKI_NDS Tiki::Debug::printf("setting TCP_NODELAY\n"); setsockopt(m_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&yes, sizeof(yes)); +#endif -#if TIKI_PLAT != TIKI_WIN32 +#if TIKI_PLAT != TIKI_WIN32 && TIKI_PLAT != TIKI_NDS if(isReuse()) { Tiki::Debug::printf("setting reuse flag\n"); setsockopt(m_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)); @@ -103,15 +105,15 @@ void TCPSocket::close() { m_open = false; Tiki::Debug::printf("closing socket\n"); + if(m_socket != INVALID_SOCKET) { #if TIKI_PLAT == TIKI_WIN32 - if(m_socket != INVALID_SOCKET) { + shutdown(m_socket, SHUT_RDWR); closesocket(m_socket); - } #else - if(m_socket != INVALID_SOCKET) { + ::shutdown(m_socket, SHUT_RDWR); ::close(m_socket); +#endif } -#endif } void TCPSocket::setNonBlocking(bool blocking) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-22 20:47:45
|
Revision: 486 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=486&view=rev Author: atani Date: 2007-08-22 13:47:44 -0700 (Wed, 22 Aug 2007) Log Message: ----------- fixing svnversion usage Modified Paths: -------------- tiki/Makefile Modified: tiki/Makefile =================================================================== --- tiki/Makefile 2007-08-22 18:08:17 UTC (rev 485) +++ tiki/Makefile 2007-08-22 20:47:44 UTC (rev 486) @@ -1,5 +1,5 @@ -SVN_VERSION_TMP=$(shell svnversion) +SVN_VERSION_TMP=$(shell svnversion .) SVN_VERSION=$(subst :,_,$(SVN_VERSION_TMP)) default: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-22 18:08:19
|
Revision: 485 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=485&view=rev Author: atani Date: 2007-08-22 11:08:17 -0700 (Wed, 22 Aug 2007) Log Message: ----------- prefix final boundry in POST with "--" Modified Paths: -------------- tiki/src/net/http/useragent.cpp Modified: tiki/src/net/http/useragent.cpp =================================================================== --- tiki/src/net/http/useragent.cpp 2007-08-22 17:46:32 UTC (rev 484) +++ tiki/src/net/http/useragent.cpp 2007-08-22 18:08:17 UTC (rev 485) @@ -143,7 +143,8 @@ socket->send(headerBuf); socket->send(buf); } - std::string footerText = req->getBoundaryMarker(); + std::string footerText = "--"; + footerText.append(req->getBoundaryMarker()); footerText.append("--\r\n"); RefPtr<Buffer> footerBuf = new Buffer(2048); footerBuf->setData((uint8 *)footerText.c_str(), footerText.size()); @@ -215,7 +216,7 @@ std::list<std::string> content = request->getContentPartNames(); if(!mode.compare("POST") && content.size() > 1) { - uint64 totalSize = request->getBoundaryMarker().size() + 4; // add 4 to account for --\r\n + uint64 totalSize = request->getBoundaryMarker().size() + 6; // add 6 to account for "--<boundary>--\r\n" for(std::list<std::string>::iterator iter = content.begin(); iter != content.end(); ++iter) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-22 17:46:36
|
Revision: 484 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=484&view=rev Author: atani Date: 2007-08-22 10:46:32 -0700 (Wed, 22 Aug 2007) Log Message: ----------- updates to support POST requests Modified Paths: -------------- tiki/examples/net/httpclient/src/main.cpp tiki/include/Tiki/net/buffer.h tiki/include/Tiki/net/http/request.h tiki/include/Tiki/net/http/useragent.h tiki/src/net/http/request.cpp tiki/src/net/http/useragent.cpp Modified: tiki/examples/net/httpclient/src/main.cpp =================================================================== --- tiki/examples/net/httpclient/src/main.cpp 2007-08-22 00:39:13 UTC (rev 483) +++ tiki/examples/net/httpclient/src/main.cpp 2007-08-22 17:46:32 UTC (rev 484) @@ -53,6 +53,7 @@ { RefPtr<Buffer> responseBuf = response->getContentPart(*iter); Tiki::Debug::printf("Content Part: %s [%u bytes]\n", (*iter).c_str(), responseBuf->getUsedDataLen()); + Tiki::Debug::printf("%s\n", responseBuf->getData()); } Modified: tiki/include/Tiki/net/buffer.h =================================================================== --- tiki/include/Tiki/net/buffer.h 2007-08-22 00:39:13 UTC (rev 483) +++ tiki/include/Tiki/net/buffer.h 2007-08-22 17:46:32 UTC (rev 484) @@ -10,6 +10,8 @@ #include "Tiki/object.h" +#include <fstream> + namespace Tiki { namespace Net { @@ -17,13 +19,14 @@ class Buffer : public Object { public: - Buffer(size_t len) { + Buffer(size_t len, std::string contentType = "application/octet-stream") : m_contentType(contentType) { m_data = new uint8[len]; memset(m_data, 0, len); m_dataLen = len; m_usedDataLen = 0; } - Buffer(size_t len, uint8 *data) { + + Buffer(size_t len, uint8 *data, std::string contentType = "application/octet-stream") : m_contentType(contentType) { m_data = new uint8[len]; memset(m_data, 0, len); m_dataLen = len; @@ -31,6 +34,16 @@ memcpy(m_data, data, len); } + Buffer(std::string filename, std::string contentType, std::string fieldName = "") : m_fileName(filename), m_contentType(contentType), m_fieldName(fieldName) { + std::ifstream stream(filename.c_str(), std::ios::in | std::ios::binary); + stream.seekg(0, std::ios::end); + m_dataLen = m_usedDataLen = stream.tellg(); + stream.seekg(0); + m_data = new uint8[m_dataLen]; + stream.read((char *)m_data, m_dataLen); + stream.close(); + } + void append(RefPtr<Buffer> buf) { uint8 * newbuf = new uint8[ m_dataLen + buf->getDataLen() ]; memcpy(newbuf, m_data, m_usedDataLen); @@ -50,6 +63,29 @@ return m_data; } + std::string getContentType() const { + return m_contentType; + } + + std::string getFileName() const { + return m_fileName; + } + + std::string getFileNameShort() const { + std::string filename = m_fileName; + while(filename.find("/") != std::string::npos) { + filename = filename.substr(filename.find("/") + 1); + } + while(filename.find("\\") != std::string::npos) { + filename = filename.substr(filename.find("\\") + 1); + } + return filename; + } + + std::string getFieldName() const { + return m_fieldName; + } + size_t getDataLen() const { return m_dataLen; } @@ -73,6 +109,9 @@ } private: + std::string m_contentType; + std::string m_fileName; + std::string m_fieldName; uint8 *m_data; size_t m_dataLen; size_t m_usedDataLen; Modified: tiki/include/Tiki/net/http/request.h =================================================================== --- tiki/include/Tiki/net/http/request.h 2007-08-22 00:39:13 UTC (rev 483) +++ tiki/include/Tiki/net/http/request.h 2007-08-22 17:46:32 UTC (rev 484) @@ -38,8 +38,13 @@ std::list<std::string> getContentPartNames() const; RefPtr<Buffer> getContentPart(std::string name) const; + std::string getBoundaryMarker() const { + return m_boundaryMarker; + } + private: std::string m_url; + std::string m_boundaryMarker; typedef std::map<std::string, std::string> StringStringMap; typedef std::map<std::string, RefPtr< Buffer > > StringBufferMap; StringStringMap m_params; Modified: tiki/include/Tiki/net/http/useragent.h =================================================================== --- tiki/include/Tiki/net/http/useragent.h 2007-08-22 00:39:13 UTC (rev 483) +++ tiki/include/Tiki/net/http/useragent.h 2007-08-22 17:46:32 UTC (rev 484) @@ -9,6 +9,7 @@ #define __TIKI_NET_HTTP_USERAGENT_H #include "Tiki/refcnt.h" +#include "Tiki/net/tcpsocket.h" #include "Tiki/net/http/cookie.h" #include "Tiki/net/http/request.h" #include "Tiki/net/http/response.h" @@ -19,6 +20,8 @@ namespace Http { +using Tiki::Net::TCP::TCPSocket; + class HttpUserAgent : public RefCnt { public: @@ -52,9 +55,9 @@ return m_cookies; } - RefPtr<Response> get(RefPtr<Request> req) const; + RefPtr<Response> get(RefPtr<Request> req); - RefPtr<Response> post(RefPtr<Request> req) const; + RefPtr<Response> post(RefPtr<Request> req); private: std::string m_userAgentName; @@ -62,6 +65,11 @@ int m_proxyPort; std::list< RefPtr< Cookie > > m_cookies; + void parseUrl(const std::string url, std::string &host, std::string &resource, int &port); + void buildRequest(const std::string host, const std::string resource, const int port, + const std::string mode, RefPtr<Request> request, std::string &requestText, + RefPtr<Address> address); + void readResponse(RefPtr<Response> response, RefPtr<TCPSocket> socket); }; Modified: tiki/src/net/http/request.cpp =================================================================== --- tiki/src/net/http/request.cpp 2007-08-22 00:39:13 UTC (rev 483) +++ tiki/src/net/http/request.cpp 2007-08-22 17:46:32 UTC (rev 484) @@ -20,6 +20,8 @@ Request::Request() { setHeaderParam("Connection", "close"); + m_boundaryMarker = "-----------------------09f911019d74e35bd84156c5635688c0"; + } void Request::setHeaderParam(std::string param, std::string value) { Modified: tiki/src/net/http/useragent.cpp =================================================================== --- tiki/src/net/http/useragent.cpp 2007-08-22 00:39:13 UTC (rev 483) +++ tiki/src/net/http/useragent.cpp 2007-08-22 17:46:32 UTC (rev 484) @@ -11,6 +11,7 @@ #include "Tiki/net/http/useragent.h" #include <sstream> +#include <math.h> namespace Tiki { @@ -47,79 +48,209 @@ setProxyPort(8080); } -RefPtr<Response> HttpUserAgent::get(RefPtr<Request> req) const { +RefPtr<Response> HttpUserAgent::get(RefPtr<Request> req) { RefPtr<TCPSocket> socket = new TCPSocket(); socket->setNonBlocking(false); RefPtr<Response> response = new Response(); response->setUrl(req->getUrl()); response->setResultCode(200); - std::string url = req->getUrl(); - std::string hostname = ""; - int port = 80; - std::string resource = "/index.html"; + std::string hostname; + int port; + std::string resource; - if(url.find("http://") == 0) { - url = url.substr(std::string("http://").length()); + parseUrl(req->getUrl(), hostname, resource, port); + + RefPtr<Address> requestAddress = new Address(); + + std::string requestText; + buildRequest(hostname, resource, port, "GET", req, requestText, requestAddress); + socket->setPeerAddress(requestAddress); + Tiki::Debug::printf("Request:\n%s", requestText.c_str()); + + socket->open(); + if(socket->isOpen()) { + Tiki::Debug::printf("Sending request...\n"); } - else if(url.find("https://") == 0) { - url = url.substr(std::string("https://").length()); + else { + Tiki::Debug::printf("connect failed\n"); + response->setResultCode(504); + return response; } - hostname = url.substr(0, url.find("/")); - if(url.find("/") != std::string::npos) { - resource = url.substr(url.find("/")); + + RefPtr<Buffer> buf = new Buffer(2048); + buf->setData((uint8 *)requestText.c_str(), requestText.size()); + socket->send(buf); + + readResponse(response, socket); + + return response; +} + +RefPtr<Response> HttpUserAgent::post(RefPtr<Request> req) { + RefPtr<TCPSocket> socket = new TCPSocket(); + socket->setNonBlocking(false); + RefPtr<Response> response = new Response(); + response->setUrl(req->getUrl()); + response->setResultCode(200); + + std::string hostname; + int port; + std::string resource; + + parseUrl(req->getUrl(), hostname, resource, port); + + RefPtr<Address> requestAddress = new Address(); + + std::string requestText; + buildRequest(hostname, resource, port, "POST", req, requestText, requestAddress); + socket->setPeerAddress(requestAddress); + Tiki::Debug::printf("Request:\n%s", requestText.c_str()); + + socket->open(); + if(socket->isOpen()) { + Tiki::Debug::printf("Sending request...\n"); } - if(hostname.find(":") != std::string::npos) { - std::string portstr = url.substr(hostname.find(":")); + else { + Tiki::Debug::printf("connect failed\n"); + response->setResultCode(504); + return response; + } + + RefPtr<Buffer> buf = new Buffer(2048); + buf->setData((uint8 *)requestText.c_str(), requestText.size()); + socket->send(buf); + + std::list<std::string> content = req->getContentPartNames(); + if(content.size() > 1) { + for(std::list<std::string>::iterator iter = content.begin(); + iter != content.end(); + ++iter) { + RefPtr<Buffer> buf = req->getContentPart(*iter); + std::stringstream temp; + temp << req->getBoundaryMarker() << "\r\n"; + temp << "Content-Disposition: form-data: name=\""; + if(buf->getFieldName().size() > 0) { + temp << buf->getFieldName(); + } + else { + temp << "File"; + } + temp << "\"; filename=\"" << buf->getFileNameShort() << "\"\r\nContent-Type: " << buf->getContentType() << "\r\n"; + RefPtr<Buffer> headerBuf = new Buffer(2048); + std::string headerText = temp.str(); + headerBuf->setData((uint8 *)headerText.c_str(), headerText.size()); + socket->send(headerBuf); + socket->send(buf); + } + std::string footerText = req->getBoundaryMarker(); + footerText.append("--\r\n"); + RefPtr<Buffer> footerBuf = new Buffer(2048); + footerBuf->setData((uint8 *)footerText.c_str(), footerText.size()); + socket->send(footerBuf); + } + else if(content.size() == 1) { + RefPtr<Buffer> buf = req->getContentPart(*content.begin()); + socket->send(buf); + } + + readResponse(response, socket); + + return response; +} + +void HttpUserAgent::parseUrl(const std::string url, std::string &host, std::string &resource, int &port) { + std::string temp_url = url; + + // set defaults + host = ""; + port = 80; + resource = "/index.html"; + + if(temp_url.find("http://") == 0) { + temp_url = temp_url.substr(std::string("http://").length()); + } + else if(temp_url.find("https://") == 0) { + temp_url = temp_url.substr(std::string("https://").length()); + } + host = temp_url.substr(0, temp_url.find("/")); + if(temp_url.find("/") != std::string::npos) { + resource = temp_url.substr(temp_url.find("/")); + } + if(host.find(":") != std::string::npos) { + std::string portstr = url.substr(host.find(":")); port = atoi(portstr.c_str()); - hostname = hostname.substr(0, hostname.find(":")); + host = host.substr(0, host.find(":")); } +} - RefPtr<Address> requestAddress = new Address(); +void HttpUserAgent::buildRequest(const std::string host, const std::string resource, const int port, + const std::string mode, RefPtr<Request> request, std::string &requestText, + RefPtr<Address> address) { - std::stringstream request; + std::stringstream req; if(m_proxyHost.empty()) { - request << "GET " << resource << " HTTP/1.1\r\n"; - request << "Host: " << hostname << "\r\n"; - requestAddress->setHostName(hostname); - requestAddress->setPort(port); + req << mode << " " << resource << " HTTP/1.1\r\n"; + req << "Host: " << host << "\r\n"; + address->setHostName(host); + address->setPort(port); } else { // proxy connection - request << "GET " << req->getUrl(); + req << mode << " " << request->getUrl(); if(port != 80) { - request << ":" << port; + req << ":" << port; } - request << " HTTP/1.1\r\n"; - request << "Host: " << hostname << "\r\n"; - requestAddress->setHostName(m_proxyHost); - requestAddress->setPort(m_proxyPort); + req << " HTTP/1.1\r\n"; + req << "Host: " << host << "\r\n"; + address->setHostName(m_proxyHost); + address->setPort(m_proxyPort); } - std::list<std::string> params = req->getHeaderParamNames(); + std::list<std::string> params = request->getHeaderParamNames(); for(std::list<string>::const_iterator param = params.begin(); param != params.end(); ++param) { - request << *param << ": " << req->getHeaderParam(*param) << "\r\n"; + req << *param << ": " << request->getHeaderParam(*param) << "\r\n"; } - request << "\r\n"; - socket->setPeerAddress(requestAddress); - Tiki::Debug::printf("Request:\n%s", request.str().c_str()); - socket->open(); - if(socket->isOpen()) { - Tiki::Debug::printf("Sending request...\n"); + std::list<std::string> content = request->getContentPartNames(); + if(!mode.compare("POST") && content.size() > 1) { + uint64 totalSize = request->getBoundaryMarker().size() + 4; // add 4 to account for --\r\n + for(std::list<std::string>::iterator iter = content.begin(); + iter != content.end(); + ++iter) { + RefPtr<Buffer> buf = request->getContentPart(*iter); + totalSize += buf->getUsedDataLen(); + std::stringstream temp; + temp << "Content-Disposition: form-data: name=\""; + if(buf->getFieldName().size() > 0) { + temp << buf->getFieldName(); + } + else { + temp << "File"; + } + temp << "\"; filename=\"" << buf->getFileNameShort() << "\"\r\nContent-Type: " << buf->getContentType() << "\r\n"; + + // add section header size + totalSize += temp.str().size(); + } + + req << "Content-Length: " << totalSize << "\r\n"; + req << "Expect: 100-continue\r\n"; + req << "Content-Type: multipart/form-data; boundary=" << request->getBoundaryMarker() << "\r\n"; } - else { - Tiki::Debug::printf("connect failed\n"); - response->setResultCode(504); - return response; + else if(!mode.compare("POST") && content.size() == 1) { + RefPtr<Buffer> buf = request->getContentPart(*content.begin()); + req << "Content-Type: " << buf->getContentType() << "\r\n"; + req << "Content-Length: " << buf->getUsedDataLen() << "\r\n"; } + req << "\r\n"; - RefPtr<Buffer> buf = new Buffer(2048); - std::string requeststr = request.str(); - buf->setData((uint8 *)requeststr.c_str(), requeststr.size()); - socket->send(buf); + Tiki::Debug::printf("Request Text: %s\n", req.str().c_str()); + requestText = req.str(); +} +void HttpUserAgent::readResponse(RefPtr<Response> response, RefPtr<TCPSocket> socket) { std::string status = ""; READ_ONE_LINE(status, socket) @@ -189,7 +320,7 @@ else { continue; } - sizeDecoded += (ch * pow(16.0f, size.size() - i - 1)); + sizeDecoded += (ch * static_cast<int>(pow(16.0f, size.size() - i - 1))); } //Tiki::Debug::printf("chunk size: %d [%s]\n", sizeDecoded, size.c_str()); if(sizeDecoded > 0) { @@ -236,14 +367,8 @@ Tiki::Debug::printf("Encoding is unknown\n"); } response->addContentPart(DEFAULT_CONTENT_PART, fullBuf); - - return response; } -RefPtr<Response> HttpUserAgent::post(RefPtr<Request> req) const { - return NULL; -} - }; // namespace Http }; // namespace Net This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-22 00:39:17
|
Revision: 483 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=483&view=rev Author: atani Date: 2007-08-21 17:39:13 -0700 (Tue, 21 Aug 2007) Log Message: ----------- use generic proxy, comment lines Modified Paths: -------------- tiki/examples/net/httpclient/src/main.cpp Modified: tiki/examples/net/httpclient/src/main.cpp =================================================================== --- tiki/examples/net/httpclient/src/main.cpp 2007-08-21 23:56:11 UTC (rev 482) +++ tiki/examples/net/httpclient/src/main.cpp 2007-08-22 00:39:13 UTC (rev 483) @@ -37,8 +37,8 @@ } RefPtr<HttpUserAgent> useragent = new HttpUserAgent(); - useragent->setProxyHost("www-proxy.us.oracle.com"); - useragent->setProxyPort(80); + //useragent->setProxyHost("proxy.example.com"); + //useragent->setProxyPort(80); RefPtr<Request> request = new Request(); request->setUrl(argv[1]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-21 23:56:18
|
Revision: 482 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=482&view=rev Author: atani Date: 2007-08-21 16:56:11 -0700 (Tue, 21 Aug 2007) Log Message: ----------- Tiki::Net::Http implementation for GET Modified Paths: -------------- tiki/include/Tiki/net/buffer.h tiki/sdl/Makefile Added Paths: ----------- tiki/examples/net/httpclient/ tiki/examples/net/httpclient/Makefile tiki/examples/net/httpclient/httpclient.vcproj tiki/examples/net/httpclient/src/ tiki/examples/net/httpclient/src/HttpClient.cpp tiki/examples/net/httpclient/src/main.cpp tiki/include/Tiki/net/http/ tiki/include/Tiki/net/http/cookie.h tiki/include/Tiki/net/http/request.h tiki/include/Tiki/net/http/response.h tiki/include/Tiki/net/http/useragent.h tiki/src/net/http/ tiki/src/net/http/request.cpp tiki/src/net/http/response.cpp tiki/src/net/http/useragent.cpp Added: tiki/examples/net/httpclient/Makefile =================================================================== --- tiki/examples/net/httpclient/Makefile (rev 0) +++ tiki/examples/net/httpclient/Makefile 2007-08-21 23:56:11 UTC (rev 482) @@ -0,0 +1,13 @@ + +TIKI_DIR=../../../ +CFLAGS=-I$(TIKI_DIR)$(TIKI_PLAT)/include -I$(TIKI_DIR)include +OBJS = $(patsubst %.cpp,%.o,$(wildcard src/*.cpp)) + +all: $(OBJS) + $(CXX) $(LDFLAGS) -L$(TIKI_DIR)$(TIKI_PLAT) -L$(TIKI_DIR)$(TIKI_PLAT)/lib $(OBJS) $(TIKI_BASE_LIBS) -o httpclient + +clean: + -rm -f $(OBJS) httpclient + +DEPSDIR=$(CURDIR) +include $(TIKI_DIR)$(TIKI_PLAT)/Makefile.rules Added: tiki/examples/net/httpclient/httpclient.vcproj =================================================================== --- tiki/examples/net/httpclient/httpclient.vcproj (rev 0) +++ tiki/examples/net/httpclient/httpclient.vcproj 2007-08-21 23:56:11 UTC (rev 482) @@ -0,0 +1,205 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="HttpClient" + ProjectGUID="{7B823C96-861C-4578-95FF-1087A45AF1AA}" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="Debug" + IntermediateDirectory="Debug" + ConfigurationType="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="$(ProjectDir)\..\..\..\win32\include;$(ProjectDir)\..\..\..\include;"C:\Program Files\OpenAL 1.1 SDK\include"" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib ws2_32.lib" + LinkIncremental="2" + AdditionalLibraryDirectories="$(ProjectDir)\..\..\..\win32\Debug;"C:\Program Files\OpenAL 1.1 SDK\libs\Win32"" + GenerateDebugInformation="true" + SubSystem="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="1" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="$(ProjectDir)\..\..\..\win32\include;$(ProjectDir)\..\..\..\include;"C:\Program Files\OpenAL 1.1 SDK\include"" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;" + RuntimeLibrary="0" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib ws2_32.lib" + LinkIncremental="1" + AdditionalLibraryDirectories="$(ProjectDir)\..\..\..\win32\Release;C:\Program Files\OpenAL 1.1 SDK\libs\Win32" + IgnoreDefaultLibraryNames="" + GenerateDebugInformation="true" + SubSystem="2" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" + > + </Filter> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\src\ChatClient.cpp" + > + </File> + <File + RelativePath=".\src\main.cpp" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Added: tiki/examples/net/httpclient/src/HttpClient.cpp =================================================================== --- tiki/examples/net/httpclient/src/HttpClient.cpp (rev 0) +++ tiki/examples/net/httpclient/src/HttpClient.cpp 2007-08-21 23:56:11 UTC (rev 482) @@ -0,0 +1,27 @@ +/* +* HttpClient.cpp +* HttpClient +* +* Copyright (C)2007 Atani Software +* +*/ + +#include <Tiki/tiki.h> +#include <pch.h> + +#if TIKI_PLAT == TIKI_WIN32 +#include <windows.h> + +static char szAppName[] = "HttpClient"; +int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) +#else +extern "C" int tiki_main( int argc, char *argv[] ); +int main( int argc, char *argv[] ) +#endif +{ +#if TIKI_PLAT != TIKI_WIN32 + return tiki_main( argc, argv ); +#else + return Tiki::DoMain( szAppName, hInst, hPrevInstance, lpCmdLine, nCmdShow ); +#endif +} Added: tiki/examples/net/httpclient/src/main.cpp =================================================================== --- tiki/examples/net/httpclient/src/main.cpp (rev 0) +++ tiki/examples/net/httpclient/src/main.cpp 2007-08-21 23:56:11 UTC (rev 482) @@ -0,0 +1,61 @@ +/* +* main.cpp +* Simple Http Client Main method +* +* Copyright (C)2007 Atani Software +* +*/ + +#include <Tiki/tiki.h> +#include <Tiki/refcnt.h> +#include <Tiki/hid.h> +#include <Tiki/tikitime.h> +#include <Tiki/net.h> +#include <Tiki/net/http/useragent.h> +#include <Tiki/net/http/request.h> + +using namespace Tiki; +using namespace Tiki::Debug; +using namespace Tiki::Net; +using namespace Tiki::Net::Http; + +volatile bool g_quitting = false; +void tkCallback( const Hid::Event & evt, void * data ) { + if ( evt.type == Hid::Event::EvtQuit ) { + g_quitting = true; + } +} + +extern "C" int tiki_main( int argc, char **argv) { + Tiki::init(argc, argv); + Tiki::Net::init(); + Hid::callbackReg( tkCallback, NULL ); + + if(argc < 2) { + Tiki::Debug::printf("Need to pass request url on commandline\n"); + return -1; + } + + RefPtr<HttpUserAgent> useragent = new HttpUserAgent(); + useragent->setProxyHost("www-proxy.us.oracle.com"); + useragent->setProxyPort(80); + + RefPtr<Request> request = new Request(); + request->setUrl(argv[1]); + + RefPtr<Response> response = useragent->get(request); + Tiki::Debug::printf("response code: %d\n", response->getResultCode()); + + std::list<std::string> content = response->getContentPartNames(); + for(std::list<std::string>::iterator iter = content.begin(); + iter != content.end(); + ++iter) + { + RefPtr<Buffer> responseBuf = response->getContentPart(*iter); + Tiki::Debug::printf("Content Part: %s [%u bytes]\n", (*iter).c_str(), responseBuf->getUsedDataLen()); + } + + + Tiki::Net::shutdown(); + return 0; +} Modified: tiki/include/Tiki/net/buffer.h =================================================================== --- tiki/include/Tiki/net/buffer.h 2007-08-21 16:14:06 UTC (rev 481) +++ tiki/include/Tiki/net/buffer.h 2007-08-21 23:56:11 UTC (rev 482) @@ -21,14 +21,26 @@ m_data = new uint8[len]; memset(m_data, 0, len); m_dataLen = len; + m_usedDataLen = 0; } Buffer(size_t len, uint8 *data) { m_data = new uint8[len]; memset(m_data, 0, len); m_dataLen = len; + m_usedDataLen = len; memcpy(m_data, data, len); } + void append(RefPtr<Buffer> buf) { + uint8 * newbuf = new uint8[ m_dataLen + buf->getDataLen() ]; + memcpy(newbuf, m_data, m_usedDataLen); + memcpy(newbuf + m_usedDataLen, buf->getData(), buf->getUsedDataLen()); + delete [] m_data; + m_data = newbuf; + m_dataLen += buf->getDataLen(); + m_usedDataLen += buf->getUsedDataLen(); + } + void reset() { memset(m_data, 0, m_dataLen); m_usedDataLen = 0; Added: tiki/include/Tiki/net/http/cookie.h =================================================================== --- tiki/include/Tiki/net/http/cookie.h (rev 0) +++ tiki/include/Tiki/net/http/cookie.h 2007-08-21 23:56:11 UTC (rev 482) @@ -0,0 +1,72 @@ +/* + Tiki + + useragent.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_HTTP_COOKIE_H +#define __TIKI_NET_HTTP_COOKIE_H + +#include "Tiki/refcnt.h" + +namespace Tiki { + +namespace Net { + +namespace Http { + +class Cookie : public RefCnt { + + public: + Cookie( std::string name, std::string value, std::string version, + std::string comment = "", long maxage = 0, std::string path = "", + bool secure = false) : + m_name(name), m_value(value), m_version(version), m_comment(comment), + m_maxage(maxage), m_path(path), m_secure(secure) {}; + + std::string getName() const { + return m_name; + } + + std::string getValue() const { + return m_value; + } + + std::string getVersion() const { + return m_version; + } + + std::string getComment() const { + return m_comment; + } + + std::string getPath() const { + return m_path; + } + + long getMaxAge() const { + return m_maxage; + } + + bool isSecure() { + return m_secure; + } + private: + std::string m_name; + std::string m_value; + std::string m_version; + std::string m_comment; + long m_maxage; + std::string m_path; + bool m_secure; +}; + + +}; // namespace Http + +}; // namespace Net + +}; // namespace Tiki + +#endif // __TIKI_NET_HTTP_COOKIE_H Added: tiki/include/Tiki/net/http/request.h =================================================================== --- tiki/include/Tiki/net/http/request.h (rev 0) +++ tiki/include/Tiki/net/http/request.h 2007-08-21 23:56:11 UTC (rev 482) @@ -0,0 +1,55 @@ +/* + Tiki + + useragent.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_HTTP_REQUEST_H +#define __TIKI_NET_HTTP_REQUEST_H + +#include "Tiki/refcnt.h" + +namespace Tiki { + +namespace Net { + +namespace Http { + +extern std::string DEFAULT_CONTENT_PART; + +class Request : public RefCnt { + public: + Request(); + + std::string getUrl() const { + return m_url; + } + + void setUrl(string url) { + m_url = url; + } + + void setHeaderParam(std::string param, std::string value); + std::string getHeaderParam(std::string param) const; + std::list<std::string> getHeaderParamNames() const; + + void addContentPart(std::string name, RefPtr<Buffer> input); + std::list<std::string> getContentPartNames() const; + RefPtr<Buffer> getContentPart(std::string name) const; + + private: + std::string m_url; + typedef std::map<std::string, std::string> StringStringMap; + typedef std::map<std::string, RefPtr< Buffer > > StringBufferMap; + StringStringMap m_params; + StringBufferMap m_parts; +}; + +}; // namespace Http + +}; // namespace Net + +}; // namespace Tiki + +#endif // __TIKI_NET_HTTP_REQUEST_H Added: tiki/include/Tiki/net/http/response.h =================================================================== --- tiki/include/Tiki/net/http/response.h (rev 0) +++ tiki/include/Tiki/net/http/response.h 2007-08-21 23:56:11 UTC (rev 482) @@ -0,0 +1,37 @@ +/* + Tiki + + useragent.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_HTTP_RESPONSE_H +#define __TIKI_NET_HTTP_RESPONSE_H + +namespace Tiki { + +namespace Net { + +namespace Http { + +class Response : public Request { + public: + Response(); + + int getResultCode() const { + return m_resultCode; + } + void setResultCode(int code) { + m_resultCode = code; + } + private: + int m_resultCode; +}; + +}; // namespace Http + +}; // namespace Net + +}; // namespace Tiki + +#endif // __TIKI_NET_HTTP_RESPONSE_H Added: tiki/include/Tiki/net/http/useragent.h =================================================================== --- tiki/include/Tiki/net/http/useragent.h (rev 0) +++ tiki/include/Tiki/net/http/useragent.h 2007-08-21 23:56:11 UTC (rev 482) @@ -0,0 +1,74 @@ +/* + Tiki + + useragent.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_HTTP_USERAGENT_H +#define __TIKI_NET_HTTP_USERAGENT_H + +#include "Tiki/refcnt.h" +#include "Tiki/net/http/cookie.h" +#include "Tiki/net/http/request.h" +#include "Tiki/net/http/response.h" + +namespace Tiki { + +namespace Net { + +namespace Http { + +class HttpUserAgent : public RefCnt { + + public: + HttpUserAgent(); + + void setUserAgentName(std::string name) { + m_userAgentName = name; + } + + std::string getUserAgentName() const { + return m_userAgentName; + } + + void setProxyHost(std::string host) { + m_proxyHost = host; + } + + std::string getProxyHost() const { + return m_proxyHost; + } + + void setProxyPort(int port) { + m_proxyPort = port; + } + + int getProxyPort() const { + return m_proxyPort; + } + + std::list< RefPtr< Cookie > > getCookies() const { + return m_cookies; + } + + RefPtr<Response> get(RefPtr<Request> req) const; + + RefPtr<Response> post(RefPtr<Request> req) const; + + private: + std::string m_userAgentName; + std::string m_proxyHost; + int m_proxyPort; + std::list< RefPtr< Cookie > > m_cookies; + + +}; + +}; // namespace Http + +}; // namespace Net + +}; // namespace Tiki + +#endif // __TIKI_NET_HTTP_USERAGENT_H Modified: tiki/sdl/Makefile =================================================================== --- tiki/sdl/Makefile 2007-08-21 16:14:06 UTC (rev 481) +++ tiki/sdl/Makefile 2007-08-21 23:56:11 UTC (rev 482) @@ -11,6 +11,7 @@ BASE_MATH_OBJ=$(patsubst %.cpp,%.o,$(wildcard ../src/math/*.cpp)) BASE_THREAD_OBJ=$(patsubst %.cpp,%.o,$(wildcard ../src/thread/*.cpp)) BASE_NET_OBJ=$(patsubst %.cpp,%.o,$(wildcard ../src/net/*.cpp)) +BASE_NET_OBJ+=$(patsubst %.cpp,%.o,$(wildcard ../src/net/http/*.cpp)) JPEG_OBJ=$(patsubst %.c,%.o,$(wildcard ../3rdparty/libjpeg/*.c)) PNG_OBJ=$(patsubst %.c,%.o,$(wildcard ../3rdparty/libpng/*.c)) @@ -58,6 +59,10 @@ examples: $(MAKE) TIKI_PLAT=sdl TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/TikiTest $(MAKE) TIKI_PLAT=sdl TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/console/TikiSnake + $(MAKE) TIKI_PLAT=sdl TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/net/basic + $(MAKE) TIKI_PLAT=sdl TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/net/chatd + $(MAKE) TIKI_PLAT=sdl TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/net/chat + $(MAKE) TIKI_PLAT=sdl TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/net/httpclient package: tar -cvf ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-sdl.tar libtiki.a Added: tiki/src/net/http/request.cpp =================================================================== --- tiki/src/net/http/request.cpp (rev 0) +++ tiki/src/net/http/request.cpp 2007-08-21 23:56:11 UTC (rev 482) @@ -0,0 +1,87 @@ +/* + Tiki + + request.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "Tiki/tiki.h" +#include "Tiki/net.h" +#include "Tiki/net/http/request.h" + +namespace Tiki { + +namespace Net { + +namespace Http { + +std::string DEFAULT_CONTENT_PART = "__TIKI__DEFAULT__"; + +Request::Request() { + setHeaderParam("Connection", "close"); +} + +void Request::setHeaderParam(std::string param, std::string value) { +// if(m_params.find(param) != m_params.end()) { +// m_params.erase(m_params.find(param)); +// } + + m_params.insert(std::make_pair(param, value)); +} + +std::string Request::getHeaderParam(std::string param) const { + if(m_params.find(param) != m_params.end()) { + return m_params.find(param)->second; + } + return ""; +} + +std::list<std::string> Request::getHeaderParamNames() const { + std::list<std::string> params; + + for( StringStringMap::const_iterator param = m_params.begin(); + param != m_params.end(); + ++param) { + + params.push_back(param->first); + } + + return params; +} + +void Request::addContentPart(std::string name, RefPtr<Buffer> input) { + //if(m_parts.find(name) != m_parts.end()) { + // m_parts.erase(m_parts.find(name)); + //} + + m_parts.insert(std::make_pair(name, input)); +} + +RefPtr<Buffer> Request::getContentPart(std::string name) const { + if(m_parts.find(name) != m_parts.end()) { + return m_parts.find(name)->second; + } + return NULL; +} + +std::list<std::string> Request::getContentPartNames() const { + std::list<std::string> parts; + + for( StringBufferMap::const_iterator part = m_parts.begin(); + part != m_parts.end(); + ++part) { + + parts.push_back(part->first); + } + + return parts; +} + + +}; // namespace Http + +}; // namespace Net + +}; // namespace Tiki + Added: tiki/src/net/http/response.cpp =================================================================== --- tiki/src/net/http/response.cpp (rev 0) +++ tiki/src/net/http/response.cpp 2007-08-21 23:56:11 UTC (rev 482) @@ -0,0 +1,28 @@ +/* + Tiki + + response.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "Tiki/tiki.h" +#include "Tiki/net.h" +#include "Tiki/net/http/request.h" +#include "Tiki/net/http/response.h" + +namespace Tiki { + +namespace Net { + +namespace Http { + +Response::Response() { +} + +}; // namespace Http + +}; // namespace Net + +}; // namespace Tiki + Added: tiki/src/net/http/useragent.cpp =================================================================== --- tiki/src/net/http/useragent.cpp (rev 0) +++ tiki/src/net/http/useragent.cpp 2007-08-21 23:56:11 UTC (rev 482) @@ -0,0 +1,252 @@ +/* + Tiki + + useragent.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "Tiki/tiki.h" +#include "Tiki/net.h" +#include "Tiki/net/http/useragent.h" + +#include <sstream> + +namespace Tiki { + +namespace Net { + +namespace Http { + +using namespace Tiki::Net::TCP; + +#define READ_ONE_LINE(res, socket) \ + { \ + RefPtr<Buffer> recvBuf = new Buffer(1); \ + char tbuf[2]; \ + res = ""; \ + while(socket->isOpen()) { \ + recvBuf->reset(); \ + socket->recv(recvBuf); \ + if(recvBuf->getUsedDataLen() > 0) { \ + tbuf[0] = recvBuf->getData()[0]; \ + tbuf[1] = '\0'; \ + if(tbuf[0] != '\n' && tbuf[0] != '\r' ) { \ + res.append((char *)tbuf); \ + } \ + else if(tbuf[0] != '\r' ) { \ + break; \ + } \ + } \ + } \ + } + +HttpUserAgent::HttpUserAgent() { + setUserAgentName("Tiki/1.0"); + setProxyHost(""); + setProxyPort(8080); +} + +RefPtr<Response> HttpUserAgent::get(RefPtr<Request> req) const { + RefPtr<TCPSocket> socket = new TCPSocket(); + socket->setNonBlocking(false); + RefPtr<Response> response = new Response(); + response->setUrl(req->getUrl()); + response->setResultCode(200); + + std::string url = req->getUrl(); + std::string hostname = ""; + int port = 80; + std::string resource = "/index.html"; + + if(url.find("http://") == 0) { + url = url.substr(std::string("http://").length()); + } + else if(url.find("https://") == 0) { + url = url.substr(std::string("https://").length()); + } + hostname = url.substr(0, url.find("/")); + if(url.find("/") != std::string::npos) { + resource = url.substr(url.find("/")); + } + if(hostname.find(":") != std::string::npos) { + std::string portstr = url.substr(hostname.find(":")); + port = atoi(portstr.c_str()); + hostname = hostname.substr(0, hostname.find(":")); + } + + RefPtr<Address> requestAddress = new Address(); + + std::stringstream request; + if(m_proxyHost.empty()) { + request << "GET " << resource << " HTTP/1.1\r\n"; + request << "Host: " << hostname << "\r\n"; + requestAddress->setHostName(hostname); + requestAddress->setPort(port); + } + else { + // proxy connection + request << "GET " << req->getUrl(); + if(port != 80) { + request << ":" << port; + } + request << " HTTP/1.1\r\n"; + request << "Host: " << hostname << "\r\n"; + requestAddress->setHostName(m_proxyHost); + requestAddress->setPort(m_proxyPort); + } + std::list<std::string> params = req->getHeaderParamNames(); + for(std::list<string>::const_iterator param = params.begin(); + param != params.end(); + ++param) { + request << *param << ": " << req->getHeaderParam(*param) << "\r\n"; + } + request << "\r\n"; + socket->setPeerAddress(requestAddress); + Tiki::Debug::printf("Request:\n%s", request.str().c_str()); + + socket->open(); + if(socket->isOpen()) { + Tiki::Debug::printf("Sending request...\n"); + } + else { + Tiki::Debug::printf("connect failed\n"); + response->setResultCode(504); + return response; + } + + RefPtr<Buffer> buf = new Buffer(2048); + std::string requeststr = request.str(); + buf->setData((uint8 *)requeststr.c_str(), requeststr.size()); + socket->send(buf); + + std::string status = ""; + READ_ONE_LINE(status, socket) + + Tiki::Debug::printf("Status: %s\n", status.c_str()); + for(int i = 0; i < status.size(); i++) { + if(status.at(i) == ' ') { + response->setResultCode(atoi(status.c_str()+i + 1)); + break; + } + } + + while(1) { + std::string line = ""; + READ_ONE_LINE(line, socket) + if(line.size() == 0) { + // done with headers + break; + } + if(line.find(":") != std::string::npos) { + std::string field = line.substr(0, line.find(":")); + std::string value = line.substr(line.find(":") + 1); + while(value.at(0) == ' ') { + value = value.substr(1); + } + + if(!field.compare("Set-Cookie")) { + + } + else { + response->setHeaderParam(field, value); + } + } + } + + RefPtr<Buffer> fullBuf = new Buffer(1); + + if(!response->getHeaderParam("Transfer-Encoding").compare("chunked")) { + Tiki::Debug::printf("Encoding is chunked\n"); + // evil chunked encoding + size_t totalSize = 0; + + long sizeDecoded = 0; + do + { + sizeDecoded = 0; + std::string size = ""; + READ_ONE_LINE(size, socket); + if(size.size() == 0) { + sizeDecoded = 1; + continue; + } + + int base = 1; + for(int i = 0; i < size.size(); i++ ) { + char ch = size.at(i); + if(ch >= 'A' && ch <= 'F') { + ch -= 'A'; + ch += 10; + } + else if(ch >= 'a' && ch <= 'f') { + ch -= 'a'; + ch += 10; + } + else if(ch >= '0' && ch <= '9') { + ch -= '0'; + } + else { + continue; + } + sizeDecoded += (ch * pow(16.0f, size.size() - i - 1)); + } + //Tiki::Debug::printf("chunk size: %d [%s]\n", sizeDecoded, size.c_str()); + if(sizeDecoded > 0) { + + RefPtr<Buffer> chunkBuf = new Buffer(sizeDecoded); + socket->recv(chunkBuf); + if(chunkBuf->getUsedDataLen() < sizeDecoded) + { + //Tiki::Debug::printf("Buffer underflow\n"); + int needed = sizeDecoded - chunkBuf->getUsedDataLen(); + while(needed > 0) { + RefPtr<Buffer> chunkBuf2 = new Buffer(needed); + socket->recv(chunkBuf2); + chunkBuf->append(chunkBuf2); + needed -= chunkBuf2->getUsedDataLen(); + } + } + totalSize += chunkBuf->getUsedDataLen(); + fullBuf->append(chunkBuf); + } + } while(sizeDecoded > 0); + Tiki::Debug::printf("total size: %d %x\n", totalSize, totalSize); + } + else if(response->getHeaderParam("Content-Length").compare("")) { + Tiki::Debug::printf("Encoding is inline\n"); + long sizeDecoded = atoi(response->getHeaderParam("Content-Length").c_str()); + Tiki::Debug::printf("decodedSize: %d\n", sizeDecoded); + + RefPtr<Buffer> chunkBuf = new Buffer(sizeDecoded); + socket->recv(chunkBuf); + if(chunkBuf->getUsedDataLen() < sizeDecoded) + { + sizeDecoded -= chunkBuf->getUsedDataLen(); + while(sizeDecoded > 0) { + RefPtr<Buffer> chunkBuf2 = new Buffer(sizeDecoded); + socket->recv(chunkBuf2); + chunkBuf->append(chunkBuf2); + sizeDecoded -= chunkBuf2->getUsedDataLen(); + } + } + fullBuf->append(chunkBuf); + } + else { + Tiki::Debug::printf("Encoding is unknown\n"); + } + response->addContentPart(DEFAULT_CONTENT_PART, fullBuf); + + return response; +} + +RefPtr<Response> HttpUserAgent::post(RefPtr<Request> req) const { + return NULL; +} + +}; // namespace Http + +}; // namespace Net + +}; // namespace Tiki + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-21 16:14:16
|
Revision: 481 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=481&view=rev Author: atani Date: 2007-08-21 09:14:06 -0700 (Tue, 21 Aug 2007) Log Message: ----------- code cleanup and fixes for chat[d] on linux Modified Paths: -------------- tiki/examples/net/chat/Makefile tiki/examples/net/chat/src/main.cpp tiki/examples/net/chatd/Makefile tiki/examples/net/chatd/src/main.cpp tiki/include/Tiki/net/tcpsocket.h tiki/sdl/src/platnet.cpp tiki/src/net/tcpserversocket.cpp tiki/src/net/tcpsocket.cpp Modified: tiki/examples/net/chat/Makefile =================================================================== --- tiki/examples/net/chat/Makefile 2007-08-21 08:33:49 UTC (rev 480) +++ tiki/examples/net/chat/Makefile 2007-08-21 16:14:06 UTC (rev 481) @@ -4,10 +4,10 @@ OBJS = $(patsubst %.cpp,%.o,$(wildcard src/*.cpp)) all: $(OBJS) - $(CXX) $(LDFLAGS) -L$(TIKI_DIR)$(TIKI_PLAT) -L$(TIKI_DIR)$(TIKI_PLAT)/lib $(OBJS) $(TIKI_BASE_LIBS) -o basic + $(CXX) $(LDFLAGS) -L$(TIKI_DIR)$(TIKI_PLAT) -L$(TIKI_DIR)$(TIKI_PLAT)/lib $(OBJS) $(TIKI_BASE_LIBS) -o chat clean: - -rm -f $(OBJS) basic + -rm -f $(OBJS) chat DEPSDIR=$(CURDIR) include $(TIKI_DIR)$(TIKI_PLAT)/Makefile.rules Modified: tiki/examples/net/chat/src/main.cpp =================================================================== --- tiki/examples/net/chat/src/main.cpp 2007-08-21 08:33:49 UTC (rev 480) +++ tiki/examples/net/chat/src/main.cpp 2007-08-21 16:14:06 UTC (rev 481) @@ -8,6 +8,7 @@ #include <Tiki/tiki.h> #include <Tiki/refcnt.h> +#include <Tiki/hid.h> #include <Tiki/tikitime.h> #include <Tiki/net.h> @@ -17,11 +18,48 @@ using namespace Tiki::Net::TCP; using namespace Tiki::Time; +RefPtr<TCPSocket> g_remoteconn; +std::string g_tmpbuf; + +volatile bool g_quitting = false; +void tkCallback( const Hid::Event & evt, void * data ) { + if ( evt.type == Hid::Event::EvtQuit ) { + g_quitting = true; + } + else if ( evt.type == Hid::Event::EvtKeyDown) { + g_tmpbuf.push_back((char)evt.key); + if(evt.key == '\n' || evt.key == '\r') { + RefPtr<Buffer> buf = new Buffer(g_tmpbuf.size()); + buf->setData((uint8 *)g_tmpbuf.c_str(), g_tmpbuf.size()); + g_remoteconn->send(buf); + g_tmpbuf = ""; + } + } +} + extern "C" int tiki_main( int argc, char **argv) { - Tiki::init(argc, argv); Tiki::Net::init(); + Hid::callbackReg( tkCallback, NULL ); + RefPtr<Address> remote = new Address(); + remote->setHostName("localhost"); + remote->setPort(5555); + g_remoteconn = new TCPSocket(remote); + + g_remoteconn->open(); + RefPtr<Buffer> buf = new Buffer(1024); + while(g_remoteconn->isOpen() && !g_quitting) { + buf->reset(); + g_remoteconn->recv(buf); + if(buf->getUsedDataLen() > 0) + { + Tiki::Debug::printf("%s", buf->getData()); + } + } + + g_remoteconn->close(); + Tiki::Net::shutdown(); return 0; } Modified: tiki/examples/net/chatd/Makefile =================================================================== --- tiki/examples/net/chatd/Makefile 2007-08-21 08:33:49 UTC (rev 480) +++ tiki/examples/net/chatd/Makefile 2007-08-21 16:14:06 UTC (rev 481) @@ -4,10 +4,10 @@ OBJS = $(patsubst %.cpp,%.o,$(wildcard src/*.cpp)) all: $(OBJS) - $(CXX) $(LDFLAGS) -L$(TIKI_DIR)$(TIKI_PLAT) -L$(TIKI_DIR)$(TIKI_PLAT)/lib $(OBJS) $(TIKI_BASE_LIBS) -o basic + $(CXX) $(LDFLAGS) -L$(TIKI_DIR)$(TIKI_PLAT) -L$(TIKI_DIR)$(TIKI_PLAT)/lib $(OBJS) $(TIKI_BASE_LIBS) -o chatd clean: - -rm -f $(OBJS) basic + -rm -f $(OBJS) chatd DEPSDIR=$(CURDIR) include $(TIKI_DIR)$(TIKI_PLAT)/Makefile.rules Modified: tiki/examples/net/chatd/src/main.cpp =================================================================== --- tiki/examples/net/chatd/src/main.cpp 2007-08-21 08:33:49 UTC (rev 480) +++ tiki/examples/net/chatd/src/main.cpp 2007-08-21 16:14:06 UTC (rev 481) @@ -72,24 +72,23 @@ { socket->send(line); } - else + else if(line->getUsedDataLen() < 0) { + Tiki::Debug::printf("socket error, closing connection\n"); socket->close(); return NULL; } if(line->getData()[0] == '/') { uint8 *data = line->getData(); - data[line->getUsedDataLen() - 1] = '\0'; - data[line->getUsedDataLen() - 2] = '\0'; string cmd = ""; - for(int i = 1; i < line->getUsedDataLen() - 2; i++) + for(int i = 0; i < line->getUsedDataLen(); i++) { cmd.push_back(data[i]); } Tiki::Debug::printf("cmd: %s\n", cmd.c_str()); - std::map<std::string, void (*)( TCPSocket * )>::const_iterator i = - g_commandHandlers.find( cmd ); + std::map<std::string, void (*)( TCPSocket * )>::const_iterator i = + g_commandHandlers.find( cmd ); if( i != g_commandHandlers.end() ){ i->second(socket); } @@ -101,6 +100,9 @@ } } } + Tiki::Debug::printf("isOpen: %s\n", socket->isOpen() ? "true" : "false"); + Tiki::Debug::printf("quitting: %s\n", quitting ? "true" : "false"); + Tiki::Debug::printf("Closing connection from: %s\n", socket->getPeerAddress()->getIPAddressString().c_str()); socket->close(); @@ -108,6 +110,7 @@ } extern "C" int tiki_main( int argc, char **argv) { + Tiki::init(argc, argv); Tiki::Net::init(); Hid::callbackReg( tkCallback, NULL ); Modified: tiki/include/Tiki/net/tcpsocket.h =================================================================== --- tiki/include/Tiki/net/tcpsocket.h 2007-08-21 08:33:49 UTC (rev 480) +++ tiki/include/Tiki/net/tcpsocket.h 2007-08-21 16:14:06 UTC (rev 481) @@ -35,7 +35,7 @@ #if TIKI_PLAT == TIKI_WIN32 TCPSocket(RefPtr<Address> address, SOCKET socket) : Socket(address), m_socket(socket), m_open(true) {setNonBlocking(false);}; #else - TCPSocket(RefPtr<Address> address, int socket) : Socket(address), m_socket(socket) {setNonBlocking(false);}; + TCPSocket(RefPtr<Address> address, int socket) : Socket(address), m_socket(socket), m_open(true) {setNonBlocking(false);}; #endif virtual void send(RefPtr<Buffer> data); Modified: tiki/sdl/src/platnet.cpp =================================================================== --- tiki/sdl/src/platnet.cpp 2007-08-21 08:33:49 UTC (rev 480) +++ tiki/sdl/src/platnet.cpp 2007-08-21 16:14:06 UTC (rev 481) @@ -7,7 +7,7 @@ */ #include "Tiki/tiki.h" -#include "Tiki/net/net.h" +#include "Tiki/net.h" namespace Tiki { Modified: tiki/src/net/tcpserversocket.cpp =================================================================== --- tiki/src/net/tcpserversocket.cpp 2007-08-21 08:33:49 UTC (rev 480) +++ tiki/src/net/tcpserversocket.cpp 2007-08-21 16:14:06 UTC (rev 481) @@ -1,28 +1,28 @@ -/* - Tiki - - tcpserversocket.cpp - - Copyright (C)2007 Atani Software -*/ - -#include "pch.h" -#include "Tiki/tiki.h" -#include "Tiki/net.h" - -namespace Tiki { - -namespace Net { - -namespace TCP { - -void TCPServerSocket::bind(size_t maxwaiting) -{ - struct sockaddr_in sock_addr; - - memset(&sock_addr, 0, sizeof(sock_addr)); - sock_addr.sin_family = AF_INET; - sock_addr.sin_addr.s_addr = INADDR_ANY; +/* + Tiki + + tcpserversocket.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "pch.h" +#include "Tiki/tiki.h" +#include "Tiki/net.h" + +namespace Tiki { + +namespace Net { + +namespace TCP { + +void TCPServerSocket::bind(size_t maxwaiting) +{ + struct sockaddr_in sock_addr; + + memset(&sock_addr, 0, sizeof(sock_addr)); + sock_addr.sin_family = AF_INET; + sock_addr.sin_addr.s_addr = INADDR_ANY; sock_addr.sin_port = htons(getPort()); if(isNonBlocking()) { @@ -34,44 +34,48 @@ fcntl(m_socket, F_SETFL, O_NONBLOCK); #endif } - - - /* Bind the socket for listening */ - if ( ::bind(m_socket, (struct sockaddr *)&sock_addr, - sizeof(sock_addr)) == SOCKET_ERROR ) { - Tiki::Debug::printf("Couldn't bind to local port\n"); - close(); - return; - } - if ( listen(m_socket, (int)maxwaiting) == SOCKET_ERROR ) { - Tiki::Debug::printf("Couldn't listen to local port\n"); - close(); - return; - } -} - -RefPtr<TCPSocket> TCPServerSocket::accept() -{ - struct sockaddr_in sock_addr; -#if TIKI_PLAT == TIKI_WIN32 - SOCKET socket; -#else - int socket; -#endif - - size_t addrlen = sizeof(struct sockaddr_in); - socket = ::accept(m_socket, (sockaddr *)&sock_addr, (int *)&addrlen); - - if(socket != INVALID_SOCKET) { - RefPtr<Address> remote = new Address(); - remote->setIPAddress(sock_addr.sin_addr.s_addr); - return new TCPSocket(remote, socket); - } - return NULL; -} - -} // namespace TCP - -} // namespace Net - -} // namespace Tiki + + + /* Bind the socket for listening */ + if ( ::bind(m_socket, (struct sockaddr *)&sock_addr, + sizeof(sock_addr)) == SOCKET_ERROR ) { + Tiki::Debug::printf("Couldn't bind to local port\n"); + close(); + return; + } + if ( listen(m_socket, (int)maxwaiting) == SOCKET_ERROR ) { + Tiki::Debug::printf("Couldn't listen to local port\n"); + close(); + return; + } +} + +RefPtr<TCPSocket> TCPServerSocket::accept() +{ + struct sockaddr_in sock_addr; +#if TIKI_PLAT == TIKI_WIN32 + SOCKET socket; +#else + int socket; +#endif + + size_t addrlen = sizeof(struct sockaddr_in); +#if TIKI_PLAT == TIKI_SDL + socket = ::accept(m_socket, (sockaddr *)&sock_addr, (socklen_t *)&addrlen); +#else + socket = ::accept(m_socket, (sockaddr *)&sock_addr, (int *)&addrlen); +#endif + + if(socket != INVALID_SOCKET) { + RefPtr<Address> remote = new Address(); + remote->setIPAddress(sock_addr.sin_addr.s_addr); + return new TCPSocket(remote, socket); + } + return NULL; +} + +} // namespace TCP + +} // namespace Net + +} // namespace Tiki Modified: tiki/src/net/tcpsocket.cpp =================================================================== --- tiki/src/net/tcpsocket.cpp 2007-08-21 08:33:49 UTC (rev 480) +++ tiki/src/net/tcpsocket.cpp 2007-08-21 16:14:06 UTC (rev 481) @@ -31,11 +31,7 @@ dataLen -= len; data += len; } - else { - Tiki::Debug::printf("sent %d bytes\n", len); - } } while(dataLen > 0 && (len > 0 || errno == EINTR)); - Tiki::Debug::printf("errno: %d [%x]\n", errno, errno); } void TCPSocket::recv(RefPtr<Buffer> data) { @@ -43,7 +39,7 @@ memset(tmp, 0, data->getDataLen()); int recvlen = 0; errno = 0; - Tiki::Debug::printf("receiving %d bytes\n", data->getDataLen()); + //Tiki::Debug::printf("receiving %d bytes\n", data->getDataLen()); do { recvlen = ::recv(m_socket, (char *)tmp, (int)data->getDataLen(), 0); #if TIKI_PLAT == TIKI_WIN32 @@ -51,12 +47,12 @@ #else } while(errno == EINTR); #endif - Tiki::Debug::printf("received %d bytes\nerrno %d\n", recvlen, errno); if(recvlen > 0) { + //Tiki::Debug::printf("received %d bytes\nerrno %d\n", recvlen, errno); data->setData(tmp, recvlen); } - else - { + else if(recvlen < 0) { + Tiki::Debug::printf("socket error, closing socket"); close(); } @@ -122,19 +118,19 @@ { Tiki::Debug::printf("%sabling blocking\n", blocking ? "dis" : "en" ); Socket::setNonBlocking(blocking); -#if TIKI_PLAT == TIKI_WIN32 - unsigned long mode = (!blocking); - ioctlsocket(m_socket, FIONBIO, &mode); -#else - int flags = fcntl(m_socket, F_GETFL, 0); - if(!blocking) - { - fcntl(m_socket, F_SETFL, flags & ~O_NONBLOCK); - } - else - { - fcntl(m_socket, F_SETFL, flags & ~O_NONBLOCK); - } +#if TIKI_PLAT == TIKI_WIN32 + unsigned long mode = (!blocking); + ioctlsocket(m_socket, FIONBIO, &mode); +#else + int flags = fcntl(m_socket, F_GETFL, 0); + if(!blocking) + { + fcntl(m_socket, F_SETFL, flags & ~O_NONBLOCK); + } + else + { + fcntl(m_socket, F_SETFL, flags | O_NONBLOCK); + } #endif } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-21 08:33:51
|
Revision: 480 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=480&view=rev Author: atani Date: 2007-08-21 01:33:49 -0700 (Tue, 21 Aug 2007) Log Message: ----------- basic chat (not implemented) and chatd (partially implemented) Added Paths: ----------- tiki/examples/net/chat/ tiki/examples/net/chat/Makefile tiki/examples/net/chat/chat.vcproj tiki/examples/net/chat/src/ tiki/examples/net/chat/src/ChatClient.cpp tiki/examples/net/chat/src/main.cpp tiki/examples/net/chatd/ tiki/examples/net/chatd/Makefile tiki/examples/net/chatd/chatd.vcproj tiki/examples/net/chatd/src/ tiki/examples/net/chatd/src/ChatServer.cpp tiki/examples/net/chatd/src/main.cpp Added: tiki/examples/net/chat/Makefile =================================================================== --- tiki/examples/net/chat/Makefile (rev 0) +++ tiki/examples/net/chat/Makefile 2007-08-21 08:33:49 UTC (rev 480) @@ -0,0 +1,13 @@ + +TIKI_DIR=../../../ +CFLAGS=-I$(TIKI_DIR)$(TIKI_PLAT)/include -I$(TIKI_DIR)include +OBJS = $(patsubst %.cpp,%.o,$(wildcard src/*.cpp)) + +all: $(OBJS) + $(CXX) $(LDFLAGS) -L$(TIKI_DIR)$(TIKI_PLAT) -L$(TIKI_DIR)$(TIKI_PLAT)/lib $(OBJS) $(TIKI_BASE_LIBS) -o basic + +clean: + -rm -f $(OBJS) basic + +DEPSDIR=$(CURDIR) +include $(TIKI_DIR)$(TIKI_PLAT)/Makefile.rules Added: tiki/examples/net/chat/chat.vcproj =================================================================== --- tiki/examples/net/chat/chat.vcproj (rev 0) +++ tiki/examples/net/chat/chat.vcproj 2007-08-21 08:33:49 UTC (rev 480) @@ -0,0 +1,205 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="ChatClient" + ProjectGUID="{7B823C96-860C-4578-95DD-1087A45AF1AA}" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="Debug" + IntermediateDirectory="Debug" + ConfigurationType="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="$(ProjectDir)\..\..\..\win32\include;$(ProjectDir)\..\..\..\include;"C:\Program Files\OpenAL 1.1 SDK\include"" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib ws2_32.lib" + LinkIncremental="2" + AdditionalLibraryDirectories="$(ProjectDir)\..\..\..\win32\Debug;"C:\Program Files\OpenAL 1.1 SDK\libs\Win32"" + GenerateDebugInformation="true" + SubSystem="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="1" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="$(ProjectDir)\..\..\..\win32\include;$(ProjectDir)\..\..\..\include;"C:\Program Files\OpenAL 1.1 SDK\include"" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;" + RuntimeLibrary="0" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib ws2_32.lib" + LinkIncremental="1" + AdditionalLibraryDirectories="$(ProjectDir)\..\..\..\win32\Release;C:\Program Files\OpenAL 1.1 SDK\libs\Win32" + IgnoreDefaultLibraryNames="" + GenerateDebugInformation="true" + SubSystem="2" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" + > + </Filter> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\src\ChatClient.cpp" + > + </File> + <File + RelativePath=".\src\main.cpp" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Added: tiki/examples/net/chat/src/ChatClient.cpp =================================================================== --- tiki/examples/net/chat/src/ChatClient.cpp (rev 0) +++ tiki/examples/net/chat/src/ChatClient.cpp 2007-08-21 08:33:49 UTC (rev 480) @@ -0,0 +1,27 @@ +/* +* Basic.cpp +* Basic Network test +* +* Copyright (C)2007 Atani Software +* +*/ + +#include <Tiki/tiki.h> +#include <pch.h> + +#if TIKI_PLAT == TIKI_WIN32 +#include <windows.h> + +static char szAppName[] = "BasicNetTest"; +int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) +#else +extern "C" int tiki_main( int argc, char *argv[] ); +int main( int argc, char *argv[] ) +#endif +{ +#if TIKI_PLAT != TIKI_WIN32 + return tiki_main( argc, argv ); +#else + return Tiki::DoMain( szAppName, hInst, hPrevInstance, lpCmdLine, nCmdShow ); +#endif +} Added: tiki/examples/net/chat/src/main.cpp =================================================================== --- tiki/examples/net/chat/src/main.cpp (rev 0) +++ tiki/examples/net/chat/src/main.cpp 2007-08-21 08:33:49 UTC (rev 480) @@ -0,0 +1,27 @@ +/* +* main.cpp +* Simple Chat Client Main method +* +* Copyright (C)2007 Atani Software +* +*/ + +#include <Tiki/tiki.h> +#include <Tiki/refcnt.h> +#include <Tiki/tikitime.h> +#include <Tiki/net.h> + +using namespace Tiki; +using namespace Tiki::Debug; +using namespace Tiki::Net; +using namespace Tiki::Net::TCP; +using namespace Tiki::Time; + +extern "C" int tiki_main( int argc, char **argv) { + + Tiki::init(argc, argv); + Tiki::Net::init(); + + Tiki::Net::shutdown(); + return 0; +} Added: tiki/examples/net/chatd/Makefile =================================================================== --- tiki/examples/net/chatd/Makefile (rev 0) +++ tiki/examples/net/chatd/Makefile 2007-08-21 08:33:49 UTC (rev 480) @@ -0,0 +1,13 @@ + +TIKI_DIR=../../../ +CFLAGS=-I$(TIKI_DIR)$(TIKI_PLAT)/include -I$(TIKI_DIR)include +OBJS = $(patsubst %.cpp,%.o,$(wildcard src/*.cpp)) + +all: $(OBJS) + $(CXX) $(LDFLAGS) -L$(TIKI_DIR)$(TIKI_PLAT) -L$(TIKI_DIR)$(TIKI_PLAT)/lib $(OBJS) $(TIKI_BASE_LIBS) -o basic + +clean: + -rm -f $(OBJS) basic + +DEPSDIR=$(CURDIR) +include $(TIKI_DIR)$(TIKI_PLAT)/Makefile.rules Added: tiki/examples/net/chatd/chatd.vcproj =================================================================== --- tiki/examples/net/chatd/chatd.vcproj (rev 0) +++ tiki/examples/net/chatd/chatd.vcproj 2007-08-21 08:33:49 UTC (rev 480) @@ -0,0 +1,205 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="ChatServer" + ProjectGUID="{7B823C96-860C-4578-95EE-1087A45AF1AA}" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="Debug" + IntermediateDirectory="Debug" + ConfigurationType="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="$(ProjectDir)\..\..\..\win32\include;$(ProjectDir)\..\..\..\include;"C:\Program Files\OpenAL 1.1 SDK\include"" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib ws2_32.lib" + LinkIncremental="2" + AdditionalLibraryDirectories="$(ProjectDir)\..\..\..\win32\Debug;"C:\Program Files\OpenAL 1.1 SDK\libs\Win32"" + GenerateDebugInformation="true" + SubSystem="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="1" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="$(ProjectDir)\..\..\..\win32\include;$(ProjectDir)\..\..\..\include;"C:\Program Files\OpenAL 1.1 SDK\include"" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;" + RuntimeLibrary="0" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib ws2_32.lib" + LinkIncremental="1" + AdditionalLibraryDirectories="$(ProjectDir)\..\..\..\win32\Release;C:\Program Files\OpenAL 1.1 SDK\libs\Win32" + IgnoreDefaultLibraryNames="" + GenerateDebugInformation="true" + SubSystem="2" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" + > + </Filter> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\src\ChatServer.cpp" + > + </File> + <File + RelativePath=".\src\main.cpp" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Added: tiki/examples/net/chatd/src/ChatServer.cpp =================================================================== --- tiki/examples/net/chatd/src/ChatServer.cpp (rev 0) +++ tiki/examples/net/chatd/src/ChatServer.cpp 2007-08-21 08:33:49 UTC (rev 480) @@ -0,0 +1,27 @@ +/* +* Basic.cpp +* Basic Network test +* +* Copyright (C)2007 Atani Software +* +*/ + +#include <Tiki/tiki.h> +#include <pch.h> + +#if TIKI_PLAT == TIKI_WIN32 +#include <windows.h> + +static char szAppName[] = "BasicNetTest"; +int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) +#else +extern "C" int tiki_main( int argc, char *argv[] ); +int main( int argc, char *argv[] ) +#endif +{ +#if TIKI_PLAT != TIKI_WIN32 + return tiki_main( argc, argv ); +#else + return Tiki::DoMain( szAppName, hInst, hPrevInstance, lpCmdLine, nCmdShow ); +#endif +} Added: tiki/examples/net/chatd/src/main.cpp =================================================================== --- tiki/examples/net/chatd/src/main.cpp (rev 0) +++ tiki/examples/net/chatd/src/main.cpp 2007-08-21 08:33:49 UTC (rev 480) @@ -0,0 +1,150 @@ +/* +* main.cpp +* Simple Chat Server Main method +* +* Copyright (C)2007 Atani Software +* +*/ + +#include <vector> +#include <Tiki/tiki.h> +#include <Tiki/hid.h> +#include <Tiki/refcnt.h> +#include <Tiki/thread.h> +#include <Tiki/tikitime.h> +#include <Tiki/net.h> + +using namespace Tiki; +using namespace Tiki::Debug; +using namespace Tiki::Net; +using namespace Tiki::Net::TCP; +using namespace Tiki::Thread; + +std::vector< RefPtr< TCPSocket > > g_threads; + +std::string g_welcomeText("Welcome to the Tiki Chat Server\nType /HELP for list of commands\n"); +std::string g_goodbyeText("So long from the Tiki Chat Server\n"); +std::string g_helpText("/HELP : this text\n/QUIT : close connection to server\n"); +std::string g_invalidCmdText("Invalid or unrecognized command\n"); + +std::map<std::string, void (*)( TCPSocket * )> g_commandHandlers; + +volatile bool quitting = false; +void tkCallback( const Hid::Event & evt, void * data ) { + if ( evt.type == Hid::Event::EvtQuit ) { + quitting = true; + } +} + +void helpCommand( TCPSocket *user ) { + RefPtr<Buffer> buf = new Buffer(g_helpText.size()); + buf->setData((uint8 *)g_helpText.c_str(), g_helpText.size()); + user->send(buf); +} + +void quitCommand( TCPSocket *user ) { + Tiki::Debug::printf("Closing connection from: %s\n", + user->getPeerAddress()->getIPAddressString().c_str()); + RefPtr<Buffer> buf = new Buffer(g_goodbyeText.size()); + buf->setData((uint8 *)g_goodbyeText.c_str(), g_goodbyeText.size()); + user->send(buf); + user->close(); +} + +void loadCommandHandlers() +{ + g_commandHandlers.clear(); + g_commandHandlers.insert(std::make_pair("HELP", &helpCommand)); + g_commandHandlers.insert(std::make_pair("QUIT", &helpCommand)); +} + +void *connectionHandler(void *param) { + RefPtr<TCPSocket> socket = ( TCPSocket * )(param); + RefPtr<Buffer> buf = new Buffer(g_welcomeText.size()); + buf->setData((uint8 *)g_welcomeText.c_str(), g_welcomeText.size()); + socket->send(buf); + + RefPtr<Buffer> line = new Buffer(1024); + while(socket->isOpen() && !quitting) { + line->reset(); + socket->recv(line); + if(line->getUsedDataLen() > 0) + { + socket->send(line); + } + else + { + socket->close(); + return NULL; + } + if(line->getData()[0] == '/') + { + uint8 *data = line->getData(); + data[line->getUsedDataLen() - 1] = '\0'; + data[line->getUsedDataLen() - 2] = '\0'; + string cmd = ""; + for(int i = 1; i < line->getUsedDataLen() - 2; i++) + { + cmd.push_back(data[i]); + } + Tiki::Debug::printf("cmd: %s\n", cmd.c_str()); + std::map<std::string, void (*)( TCPSocket * )>::const_iterator i = + g_commandHandlers.find( cmd ); + if( i != g_commandHandlers.end() ){ + i->second(socket); + } + else + { + RefPtr<Buffer> tmpBuf = new Buffer(g_invalidCmdText.size()); + tmpBuf->setData((uint8 *)g_helpText.c_str(), g_invalidCmdText.size()); + socket->send(tmpBuf); + } + } + } + Tiki::Debug::printf("Closing connection from: %s\n", + socket->getPeerAddress()->getIPAddressString().c_str()); + socket->close(); + return NULL; +} + +extern "C" int tiki_main( int argc, char **argv) { + Tiki::Net::init(); + + Hid::callbackReg( tkCallback, NULL ); + + loadCommandHandlers(); + + RefPtr<Address> local = new Address(); + local->setHostName("localhost"); + local->setIPAddress(Address::AddressAny); + RefPtr<TCPServerSocket> server = new TCPServerSocket(local); + server->setLocalAddress(local); + server->setPort(5555); + + server->open(); + + if(server->isOpen()) + { + server->bind(); + Tiki::Debug::printf("Listening on: %s/%u\n", + server->getLocalAddress()->getIPAddressString().c_str(), + server->getPort()); + if(server->isOpen()) { + + while(!quitting) { + RefPtr<TCPSocket> newsocket = server->accept(); + if(newsocket != NULL) { + Tiki::Debug::printf("New connection from: %s\n", + newsocket->getPeerAddress()->getIPAddressString().c_str()); + newsocket->ref(); + g_threads.push_back( newsocket ); + thread_t thread; + Tiki::Thread::create(&thread, &connectionHandler, newsocket); + } + } + } + } + + Tiki::Net::shutdown(); + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-21 08:30:16
|
Revision: 479 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=479&view=rev Author: atani Date: 2007-08-21 01:30:14 -0700 (Tue, 21 Aug 2007) Log Message: ----------- various cleanups and fixes for TCPServerSocket Modified Paths: -------------- tiki/examples/net/basic/src/main.cpp tiki/include/Tiki/net/buffer.h tiki/include/Tiki/net/socket.h tiki/include/Tiki/net/tcpserversocket.h tiki/include/Tiki/net/tcpsocket.h tiki/osx/include/Tiki/platnet.h tiki/osx/src/platnet.cpp tiki/src/net/address.cpp tiki/src/net/socket.cpp tiki/src/net/tcpserversocket.cpp tiki/src/net/tcpsocket.cpp tiki/win32/include/Tiki/platnet.h tiki/win32/src/platnet.cpp tiki/win32/tiki_vc80.sln Added Paths: ----------- tiki/include/Tiki/net.h Removed Paths: ------------- tiki/include/Tiki/net/net.h Modified: tiki/examples/net/basic/src/main.cpp =================================================================== --- tiki/examples/net/basic/src/main.cpp 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/examples/net/basic/src/main.cpp 2007-08-21 08:30:14 UTC (rev 479) @@ -9,7 +9,7 @@ #include <Tiki/tiki.h> #include <Tiki/refcnt.h> #include <Tiki/tikitime.h> -#include <Tiki/net/net.h> +#include <Tiki/net.h> using namespace Tiki; using namespace Tiki::Debug; Modified: tiki/include/Tiki/net/buffer.h =================================================================== --- tiki/include/Tiki/net/buffer.h 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/include/Tiki/net/buffer.h 2007-08-21 08:30:14 UTC (rev 479) @@ -29,6 +29,11 @@ memcpy(m_data, data, len); } + void reset() { + memset(m_data, 0, m_dataLen); + m_usedDataLen = 0; + } + uint8 *getData() const { return m_data; } Deleted: tiki/include/Tiki/net/net.h =================================================================== --- tiki/include/Tiki/net/net.h 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/include/Tiki/net/net.h 2007-08-21 08:30:14 UTC (rev 479) @@ -1,31 +0,0 @@ -/* - Tiki - - net.h - - Copyright (C)2007 Atani Software -*/ -#ifndef __TIKI_NET_H -#define __TIKI_NET_H - -#include "Tiki/platnet.h" - -namespace Tiki { - -namespace Net { - -void init(); -void shutdown(); - -} // namespace Net - -} // namespace Tiki - -#endif // __TIKI_NET_H - -#include <Tiki/net/address.h> -#include <Tiki/net/buffer.h> -#include <Tiki/net/socket.h> -#include <Tiki/net/tcpsocket.h> -#include <Tiki/net/tcpserversocket.h> -#include <Tiki/net/udpsocket.h> Modified: tiki/include/Tiki/net/socket.h =================================================================== --- tiki/include/Tiki/net/socket.h 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/include/Tiki/net/socket.h 2007-08-21 08:30:14 UTC (rev 479) @@ -37,12 +37,17 @@ return m_localAddress; } + void setLocalAddress(RefPtr<Address> address) + { + m_localAddress = address; + } + bool isNonBlocking() { return m_blocking; } - void setNonBlocking(bool blocking) + virtual void setNonBlocking(bool blocking) { m_blocking = blocking; } @@ -65,6 +70,8 @@ virtual void close() = 0; + virtual bool isOpen() = 0; + private: RefPtr<Address> m_peerAddress; RefPtr<Address> m_localAddress; Modified: tiki/include/Tiki/net/tcpserversocket.h =================================================================== --- tiki/include/Tiki/net/tcpserversocket.h 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/include/Tiki/net/tcpserversocket.h 2007-08-21 08:30:14 UTC (rev 479) @@ -22,7 +22,7 @@ TCPServerSocket() : TCPSocket() {}; TCPServerSocket(RefPtr<Address> address) : TCPSocket(address) {}; - void bind(); + void bind(size_t maxwaiting = 10); RefPtr<TCPSocket> accept(); }; Modified: tiki/include/Tiki/net/tcpsocket.h =================================================================== --- tiki/include/Tiki/net/tcpsocket.h 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/include/Tiki/net/tcpsocket.h 2007-08-21 08:30:14 UTC (rev 479) @@ -30,13 +30,22 @@ SOCKET_ERROR = -1 }; #endif - TCPSocket() : Socket() {}; - TCPSocket(RefPtr<Address> address) : Socket(address) {}; + TCPSocket() : Socket(), m_open(false) {}; + TCPSocket(RefPtr<Address> address) : Socket(address), m_open(false) {}; +#if TIKI_PLAT == TIKI_WIN32 + TCPSocket(RefPtr<Address> address, SOCKET socket) : Socket(address), m_socket(socket), m_open(true) {setNonBlocking(false);}; +#else + TCPSocket(RefPtr<Address> address, int socket) : Socket(address), m_socket(socket) {setNonBlocking(false);}; +#endif virtual void send(RefPtr<Buffer> data); virtual void recv(RefPtr<Buffer> data); + virtual bool isOpen() { + return m_open; + } + uint32 getPort() { return m_port; @@ -50,11 +59,12 @@ virtual void close(); - private: + virtual void setNonBlocking(bool blocking); + + protected: uint32 m_port; -#if TIKI_PLAT == TIKI_OSX - ; -#elif TIKI_PLAT == TIKI_WIN32 + bool m_open; +#if TIKI_PLAT == TIKI_WIN32 SOCKET m_socket; #else int m_socket; Copied: tiki/include/Tiki/net.h (from rev 476, tiki/include/Tiki/net/net.h) =================================================================== --- tiki/include/Tiki/net.h (rev 0) +++ tiki/include/Tiki/net.h 2007-08-21 08:30:14 UTC (rev 479) @@ -0,0 +1,30 @@ +/* + Tiki + + net.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_H +#define __TIKI_NET_H + +namespace Tiki { + +namespace Net { + +void init(); +void shutdown(); + +} // namespace Net + +} // namespace Tiki + +#endif // __TIKI_NET_H + +#include "Tiki/platnet.h" +#include "Tiki/net/address.h" +#include "Tiki/net/buffer.h" +#include "Tiki/net/socket.h" +#include "Tiki/net/tcpsocket.h" +#include "Tiki/net/tcpserversocket.h" +#include "Tiki/net/udpsocket.h" Modified: tiki/osx/include/Tiki/platnet.h =================================================================== --- tiki/osx/include/Tiki/platnet.h 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/osx/include/Tiki/platnet.h 2007-08-21 08:30:14 UTC (rev 479) @@ -8,26 +8,16 @@ #ifndef TIKI_PLATFORM_NET_H #define TIKI_PLATFORM_NET_H -#include <OpenTransport.h> -#include <OpenTptInternet.h> -#include <Events.h> -namespace Tiki { +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <netinet/in.h> +#include <netinet/tcp.h> +#include <netdb.h> +#include <sys/socket.h> +#include <sys/time.h> -namespace Net { - -enum DNS_STATUS { - NOT_READY = 0, - READY, - RESOLVED, - ERROR -}; - -extern DNS_STATUS g_tikiDNSStatus; -extern InetSvcRef g_tikiDNSRef; - -}; // namespace Net - -}; // namespace Tiki - #endif // TIKI_PLATFORM_NET_H Modified: tiki/osx/src/platnet.cpp =================================================================== --- tiki/osx/src/platnet.cpp 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/osx/src/platnet.cpp 2007-08-21 08:30:14 UTC (rev 479) @@ -13,70 +13,12 @@ namespace Net { -DNS_STATUS g_tikiDNSStatus; -InetSvcRef g_tikiDNSRef; - -static pascal void dnsNotifier(void *context, OTEventCode code, OTResult result, void *cookie) { - switch(code) { - case T_OPENCOMPLETE: - if(result == kOTNoError) { - g_tikiDNSStatus = READY; - g_tikiDNSRef = (InetSvcRef)cookie; - } - else { - g_tikiDNSStatus = ERROR; - Tiki::Debug::printf("T_DNRSTRINGTOADDRCOMPLETE event returned an error\n"); - } - break; - case T_DNRSTRINGTOADDRCOMPLETE: - g_tikiDNSStatus = RESOLVED; - break; - default: - if(result != kOTNoError) { - g_tikiDNSStatus = ERROR; - Tiki::Debug::printf("Error in DNS Resolver\n"); - } - } -} - -void startDNS() { - OSStatus status; - - status = OTAsyncOpenInternetServices( - kDefaultInternetServicesPath, 0, dnsNotifier, NULL); - if(status != noErr) { - Tiki::Debug::printf("Unable to initialize DNS Handler\n"); - } -} - -void stopDNS() { - if(g_dnsRef != 0) { - OTCloseProvider(g_tikiDNSRef); - g_tikiDNSStatus = NOT_READY; - g_tikiDNSRef = 0; - } -} - void init() { - OSStatus status; - - g_tikiDNSStatus = NOT_READY; - g_tikiDNSRef = 0; - - status = InitOpenTransport(); - if(status == noErr) { - StartDNS(); - } - else { - Tiki::Debug::printf("Unable to initialize OpenTransport\n"); - } } void shutdown() { - stopDNS(); } +}; // namespace Net -} - -}; +}; // namespace Tiki Modified: tiki/src/net/address.cpp =================================================================== --- tiki/src/net/address.cpp 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/src/net/address.cpp 2007-08-21 08:30:14 UTC (rev 479) @@ -8,7 +8,7 @@ #include "pch.h" #include "Tiki/tiki.h" -#include "Tiki/net/net.h" +#include "Tiki/net.h" #include <sstream> @@ -31,28 +31,11 @@ m_ip != AddressAny && m_ip != AddressNone ) { -#if TIKI_PLAT == TIKI_OSX - InetHost ip; - InetDomainName domainName; - OSStatus status; - - domainName[0] = '\0'; - ip = m_ip; - status = OTInetAddressToName(g_tikiDNSRef, ip, domainName); - if(status == kOTNoError) { - while(g_tikiDNSStatus != RESOLVED) - { - ; - } - return domainName; - } -#else struct hostent *hp = gethostbyaddr((char *)&m_ip, 4, AF_INET); if(hp != NULL) { m_hostname = string(hp->h_name); } -#endif } return m_hostname; @@ -69,22 +52,11 @@ if(m_ip == AddressUnknown) { Tiki::Debug::printf("resolving host: %s\n", m_hostname.c_str()); -#if TIKI_PLAT == TIKI_OSX - InetHostInfo host; - if(OTInetStringToAddress(g_tikiDNSRef, m_hostname.c_str(), &info) == noErr) { - while( g_tikiDNSStatus != RESOLVED) - { - WaitNextEvent(everyEvent, 0, 1, NULL); - } - return info.addrs[0]; - } -#else struct hostent *hp = gethostbyname(m_hostname.c_str()); if(hp != NULL) { memcpy(&m_ip, hp->h_addr, hp->h_length); } -#endif } return m_ip; } @@ -102,7 +74,6 @@ uint32 ipnums = getIPAddress(); uint8 *ip = (uint8 *)(&ipnums); - //Tiki::Debug::printf("host ip: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]); std::ostringstream address; Modified: tiki/src/net/socket.cpp =================================================================== --- tiki/src/net/socket.cpp 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/src/net/socket.cpp 2007-08-21 08:30:14 UTC (rev 479) @@ -8,7 +8,7 @@ #include "pch.h" #include "Tiki/tiki.h" -#include "Tiki/net/net.h" +#include "Tiki/net.h" namespace Tiki { Modified: tiki/src/net/tcpserversocket.cpp =================================================================== --- tiki/src/net/tcpserversocket.cpp 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/src/net/tcpserversocket.cpp 2007-08-21 08:30:14 UTC (rev 479) @@ -1,33 +1,77 @@ -/* - Tiki +/* + Tiki + + tcpserversocket.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "pch.h" +#include "Tiki/tiki.h" +#include "Tiki/net.h" + +namespace Tiki { + +namespace Net { + +namespace TCP { + +void TCPServerSocket::bind(size_t maxwaiting) +{ + struct sockaddr_in sock_addr; + + memset(&sock_addr, 0, sizeof(sock_addr)); + sock_addr.sin_family = AF_INET; + sock_addr.sin_addr.s_addr = INADDR_ANY; + sock_addr.sin_port = htons(getPort()); - tcpserversocket.cpp - - Copyright (C)2007 Atani Software -*/ - -#include "pch.h" -#include "Tiki/tiki.h" -#include "Tiki/net/net.h" - -namespace Tiki { - -namespace Net { - -namespace TCP { - -void TCPServerSocket::bind() -{ - -} - -RefPtr<TCPSocket> TCPServerSocket::accept() -{ - return NULL; -} - -} // namespace TCP - -} // namespace Net - -} // namespace Tiki + if(isNonBlocking()) { + Tiki::Debug::printf("setting NO BLOCKING mode\n"); +#if TIKI_PLAT == TIKI_WIN32 + unsigned long mode = 1; + ioctlsocket(m_socket, FIONBIO, &mode); +#else + fcntl(m_socket, F_SETFL, O_NONBLOCK); +#endif + } + + + /* Bind the socket for listening */ + if ( ::bind(m_socket, (struct sockaddr *)&sock_addr, + sizeof(sock_addr)) == SOCKET_ERROR ) { + Tiki::Debug::printf("Couldn't bind to local port\n"); + close(); + return; + } + if ( listen(m_socket, (int)maxwaiting) == SOCKET_ERROR ) { + Tiki::Debug::printf("Couldn't listen to local port\n"); + close(); + return; + } +} + +RefPtr<TCPSocket> TCPServerSocket::accept() +{ + struct sockaddr_in sock_addr; +#if TIKI_PLAT == TIKI_WIN32 + SOCKET socket; +#else + int socket; +#endif + + size_t addrlen = sizeof(struct sockaddr_in); + socket = ::accept(m_socket, (sockaddr *)&sock_addr, (int *)&addrlen); + + if(socket != INVALID_SOCKET) { + RefPtr<Address> remote = new Address(); + remote->setIPAddress(sock_addr.sin_addr.s_addr); + return new TCPSocket(remote, socket); + } + return NULL; +} + +} // namespace TCP + +} // namespace Net + +} // namespace Tiki Modified: tiki/src/net/tcpsocket.cpp =================================================================== --- tiki/src/net/tcpsocket.cpp 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/src/net/tcpsocket.cpp 2007-08-21 08:30:14 UTC (rev 479) @@ -8,7 +8,7 @@ #include "pch.h" #include "Tiki/tiki.h" -#include "Tiki/net/net.h" +#include "Tiki/net.h" #include <errno.h> @@ -19,8 +19,6 @@ namespace TCP { void TCPSocket::send(const RefPtr<Buffer> buffer) { -#if TIKI_PLAT == TIKI_OSX -#else uint8 *data = buffer->getData(); size_t dataLen = buffer->getUsedDataLen(); int len; @@ -38,39 +36,47 @@ } } while(dataLen > 0 && (len > 0 || errno == EINTR)); Tiki::Debug::printf("errno: %d [%x]\n", errno, errno); -#endif } void TCPSocket::recv(RefPtr<Buffer> data) { -#if TIKI_PLAT == TIKI_OSX -#else uint8 *tmp = new uint8[data->getDataLen()]; memset(tmp, 0, data->getDataLen()); int recvlen = 0; errno = 0; + Tiki::Debug::printf("receiving %d bytes\n", data->getDataLen()); do { - Tiki::Debug::printf("receiving %d bytes\n", data->getDataLen()); recvlen = ::recv(m_socket, (char *)tmp, (int)data->getDataLen(), 0); - } while(errno == EINTR && (recvlen < 0 && !isNonBlocking())); +#if TIKI_PLAT == TIKI_WIN32 + } while(recvlen == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK); +#else + } while(errno == EINTR); +#endif Tiki::Debug::printf("received %d bytes\nerrno %d\n", recvlen, errno); if(recvlen > 0) { data->setData(tmp, recvlen); } -#endif + else + { + close(); + } + delete [] tmp; } void TCPSocket::open() { -#if TIKI_PLAT == TIKI_OSX -#else struct sockaddr_in sock_addr; m_socket = socket(AF_INET, SOCK_STREAM, 0); if(m_socket == INVALID_SOCKET) { Tiki::Debug::printf("Error opening socket\n"); + m_open = false; return; } + int yes = 1; + Tiki::Debug::printf("setting TCP_NODELAY\n"); + setsockopt(m_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&yes, sizeof(yes)); + #if TIKI_PLAT != TIKI_WIN32 if(isReuse()) { Tiki::Debug::printf("setting reuse flag\n"); @@ -78,9 +84,10 @@ } #endif - if(!(getLocalAddress()->getIPAddress() == Address::AddressAny || - getLocalAddress()->getIPAddress() == Address::AddressNone || - getLocalAddress()->getIPAddress() == Address::AddressBroadcast)) { + if(getPeerAddress() != NULL && + !(getPeerAddress()->getIPAddress() == Address::AddressAny || + getPeerAddress()->getIPAddress() == Address::AddressNone || + getPeerAddress()->getIPAddress() == Address::AddressBroadcast)) { // connecting to remote address memset(&sock_addr, 0, sizeof(struct sockaddr_in)); sock_addr.sin_family = AF_INET; @@ -94,36 +101,44 @@ } Tiki::Debug::printf("Connected..\n"); } - - Tiki::Debug::printf("setting TCP_NODELAY\n"); - setsockopt(m_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&yes, sizeof(yes)); - - if(isNonBlocking()) { - Tiki::Debug::printf("setting NO BLOCKING mode\n"); -#if TIKI_PLAT == TIKI_WIN32 - unsigned long mode = 1; - ioctlsocket(m_socket, FIONBIO, &mode); -#else - fcntl(m_socket, F_SETFL, O_NONBLOCK); -#endif - } -#endif + m_open = true; } void TCPSocket::close() { + m_open = false; Tiki::Debug::printf("closing socket\n"); -#if TIKI_PLAT == TIKI_OSX -#elif TIKI_PLAT == TIKI_WIN32 +#if TIKI_PLAT == TIKI_WIN32 if(m_socket != INVALID_SOCKET) { closesocket(m_socket); } #else if(m_socket != INVALID_SOCKET) { ::close(m_socket); - } + } #endif } +void TCPSocket::setNonBlocking(bool blocking) +{ + Tiki::Debug::printf("%sabling blocking\n", blocking ? "dis" : "en" ); + Socket::setNonBlocking(blocking); +#if TIKI_PLAT == TIKI_WIN32 + unsigned long mode = (!blocking); + ioctlsocket(m_socket, FIONBIO, &mode); +#else + int flags = fcntl(m_socket, F_GETFL, 0); + if(!blocking) + { + fcntl(m_socket, F_SETFL, flags & ~O_NONBLOCK); + } + else + { + fcntl(m_socket, F_SETFL, flags & ~O_NONBLOCK); + } +#endif + +} + } // namespace TCP } // namespace Net Modified: tiki/win32/include/Tiki/platnet.h =================================================================== --- tiki/win32/include/Tiki/platnet.h 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/win32/include/Tiki/platnet.h 2007-08-21 08:30:14 UTC (rev 479) @@ -1,3 +1,14 @@ +/* + Tiki + + platnet.h + + Copyright (C)2007 Atani Software +*/ + +#ifndef TIKI_PLATFORM_NET_H +#define TIKI_PLATFORM_NET_H + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -3,3 +14,5 @@ #include <fcntl.h> -#include <winsock2.h> \ No newline at end of file +#include <winsock2.h> + +#endif // TIKI_PLATFORM_NET_H Modified: tiki/win32/src/platnet.cpp =================================================================== --- tiki/win32/src/platnet.cpp 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/win32/src/platnet.cpp 2007-08-21 08:30:14 UTC (rev 479) @@ -8,7 +8,7 @@ #include "pch.h" #include "Tiki/tiki.h" -#include "Tiki/net/net.h" +#include "Tiki/net.h" namespace Tiki { Modified: tiki/win32/tiki_vc80.sln =================================================================== --- tiki/win32/tiki_vc80.sln 2007-08-21 04:55:20 UTC (rev 478) +++ tiki/win32/tiki_vc80.sln 2007-08-21 08:30:14 UTC (rev 479) @@ -18,6 +18,16 @@ {F2816CAC-B560-4ED9-8A73-9635F832943C} = {F2816CAC-B560-4ED9-8A73-9635F832943C} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ChatClient", "..\examples\net\chat\chat.vcproj", "{7B823C96-860C-4578-95DD-1087A45AF1AA}" + ProjectSection(ProjectDependencies) = postProject + {F2816CAC-B560-4ED9-8A73-9635F832943C} = {F2816CAC-B560-4ED9-8A73-9635F832943C} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ChatServer", "..\examples\net\chatd\chatd.vcproj", "{7B823C96-860C-4578-95EE-1087A45AF1AA}" + ProjectSection(ProjectDependencies) = postProject + {F2816CAC-B560-4ED9-8A73-9635F832943C} = {F2816CAC-B560-4ED9-8A73-9635F832943C} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -40,6 +50,14 @@ {7B823C96-860C-4578-95CC-1087A45AF1AA}.Debug|Win32.Build.0 = Debug|Win32 {7B823C96-860C-4578-95CC-1087A45AF1AA}.Release|Win32.ActiveCfg = Release|Win32 {7B823C96-860C-4578-95CC-1087A45AF1AA}.Release|Win32.Build.0 = Release|Win32 + {7B823C96-860C-4578-95DD-1087A45AF1AA}.Debug|Win32.ActiveCfg = Debug|Win32 + {7B823C96-860C-4578-95DD-1087A45AF1AA}.Debug|Win32.Build.0 = Debug|Win32 + {7B823C96-860C-4578-95DD-1087A45AF1AA}.Release|Win32.ActiveCfg = Release|Win32 + {7B823C96-860C-4578-95DD-1087A45AF1AA}.Release|Win32.Build.0 = Release|Win32 + {7B823C96-860C-4578-95EE-1087A45AF1AA}.Debug|Win32.ActiveCfg = Debug|Win32 + {7B823C96-860C-4578-95EE-1087A45AF1AA}.Debug|Win32.Build.0 = Debug|Win32 + {7B823C96-860C-4578-95EE-1087A45AF1AA}.Release|Win32.ActiveCfg = Release|Win32 + {7B823C96-860C-4578-95EE-1087A45AF1AA}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-21 04:55:22
|
Revision: 478 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=478&view=rev Author: atani Date: 2007-08-20 21:55:20 -0700 (Mon, 20 Aug 2007) Log Message: ----------- adding BasicNet example to win32 examples target and package target. Modified Paths: -------------- tiki/win32/Makefile Modified: tiki/win32/Makefile =================================================================== --- tiki/win32/Makefile 2007-08-21 04:26:46 UTC (rev 477) +++ tiki/win32/Makefile 2007-08-21 04:55:20 UTC (rev 478) @@ -1,16 +1,14 @@ all: - vcbuild /nocolor /rebuild tiki_vs80.vcproj Debug - vcbuild /nocolor /rebuild tiki_vs80.vcproj Release + vcbuild /nocolor /rebuild tiki_vs80.vcproj $$ALL clean: -vcbuild /nocolor /clean tiki_vc80.sln $$ALL examples: - vcbuild /nocolor /rebuild ..\\examples\\TikiTest\\TikiTest_vc80.vcproj Debug - vcbuild /nocolor /rebuild ..\\examples\\TikiTest\\TikiTest_vc80.vcproj Release - vcbuild /nocolor /rebuild ..\\examples\\console\\TikiSnake\\TikiSnake.vcproj Debug - vcbuild /nocolor /rebuild ..\\examples\\console\\TikiSnake\\TikiSnake.vcproj Release + vcbuild /nocolor /rebuild ..\\examples\\TikiTest\\TikiTest_vc80.vcproj $$ALL + vcbuild /nocolor /rebuild ..\\examples\\console\\TikiSnake\\TikiSnake.vcproj $$ALL + vcbuild /nocolor /rebuild ..\\examples\\net\\basic\\basic.vcproj $$ALL package: zip -9r ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-win32-Debug.zip Debug/tiki.lib @@ -19,6 +17,7 @@ include \ win32/include \ examples/TikiTest/Debug/tikitest.exe \ + examples/net/basic/Debug/BasicNet.exe \ examples/console/TikiSnake/Debug/tikisnake.exe \ examples/console/TikiSnake/Debug/pc-ascii.png \ -x "*/.svn/*" @@ -28,6 +27,7 @@ include \ win32/include \ examples/TikiTest/Release/tikitest.exe \ + examples/net/basic/Release/BasicNet.exe \ examples/console/TikiSnake/Release/tikisnake.exe \ examples/console/TikiSnake/Release/pc-ascii.png \ -x "*/.svn/*" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-21 04:26:48
|
Revision: 477 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=477&view=rev Author: atani Date: 2007-08-20 21:26:46 -0700 (Mon, 20 Aug 2007) Log Message: ----------- fix paths.. Modified Paths: -------------- tiki/src/net/address.cpp tiki/src/net/socket.cpp tiki/src/net/tcpserversocket.cpp tiki/src/net/tcpsocket.cpp Modified: tiki/src/net/address.cpp =================================================================== --- tiki/src/net/address.cpp 2007-08-21 04:24:11 UTC (rev 476) +++ tiki/src/net/address.cpp 2007-08-21 04:26:46 UTC (rev 477) @@ -8,7 +8,7 @@ #include "pch.h" #include "Tiki/tiki.h" -#include "Tiki/net.h" +#include "Tiki/net/net.h" #include <sstream> Modified: tiki/src/net/socket.cpp =================================================================== --- tiki/src/net/socket.cpp 2007-08-21 04:24:11 UTC (rev 476) +++ tiki/src/net/socket.cpp 2007-08-21 04:26:46 UTC (rev 477) @@ -8,7 +8,7 @@ #include "pch.h" #include "Tiki/tiki.h" -#include "Tiki/net.h" +#include "Tiki/net/net.h" namespace Tiki { Modified: tiki/src/net/tcpserversocket.cpp =================================================================== --- tiki/src/net/tcpserversocket.cpp 2007-08-21 04:24:11 UTC (rev 476) +++ tiki/src/net/tcpserversocket.cpp 2007-08-21 04:26:46 UTC (rev 477) @@ -8,7 +8,7 @@ #include "pch.h" #include "Tiki/tiki.h" -#include "Tiki/net.h" +#include "Tiki/net/net.h" namespace Tiki { Modified: tiki/src/net/tcpsocket.cpp =================================================================== --- tiki/src/net/tcpsocket.cpp 2007-08-21 04:24:11 UTC (rev 476) +++ tiki/src/net/tcpsocket.cpp 2007-08-21 04:26:46 UTC (rev 477) @@ -8,7 +8,7 @@ #include "pch.h" #include "Tiki/tiki.h" -#include "Tiki/net.h" +#include "Tiki/net/net.h" #include <errno.h> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-21 04:24:13
|
Revision: 476 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=476&view=rev Author: atani Date: 2007-08-20 21:24:11 -0700 (Mon, 20 Aug 2007) Log Message: ----------- oops, correct includes Modified Paths: -------------- tiki/include/Tiki/net/net.h tiki/src/net/address.cpp tiki/src/net/socket.cpp tiki/src/net/tcpserversocket.cpp tiki/src/net/tcpsocket.cpp Modified: tiki/include/Tiki/net/net.h =================================================================== --- tiki/include/Tiki/net/net.h 2007-08-21 04:08:54 UTC (rev 475) +++ tiki/include/Tiki/net/net.h 2007-08-21 04:24:11 UTC (rev 476) @@ -23,6 +23,9 @@ #endif // __TIKI_NET_H +#include <Tiki/net/address.h> #include <Tiki/net/buffer.h> -#include <Tiki/net/address.h> +#include <Tiki/net/socket.h> #include <Tiki/net/tcpsocket.h> +#include <Tiki/net/tcpserversocket.h> +#include <Tiki/net/udpsocket.h> Modified: tiki/src/net/address.cpp =================================================================== --- tiki/src/net/address.cpp 2007-08-21 04:08:54 UTC (rev 475) +++ tiki/src/net/address.cpp 2007-08-21 04:24:11 UTC (rev 476) @@ -8,8 +8,7 @@ #include "pch.h" #include "Tiki/tiki.h" -#include "Tiki/platnet.h" -#include "Tiki/net/address.h" +#include "Tiki/net.h" #include <sstream> Modified: tiki/src/net/socket.cpp =================================================================== --- tiki/src/net/socket.cpp 2007-08-21 04:08:54 UTC (rev 475) +++ tiki/src/net/socket.cpp 2007-08-21 04:24:11 UTC (rev 476) @@ -8,8 +8,7 @@ #include "pch.h" #include "Tiki/tiki.h" -#include "Tiki/platnet.h" -#include "Tiki/net/socket.h" +#include "Tiki/net.h" namespace Tiki { Modified: tiki/src/net/tcpserversocket.cpp =================================================================== --- tiki/src/net/tcpserversocket.cpp 2007-08-21 04:08:54 UTC (rev 475) +++ tiki/src/net/tcpserversocket.cpp 2007-08-21 04:24:11 UTC (rev 476) @@ -8,8 +8,7 @@ #include "pch.h" #include "Tiki/tiki.h" -#include "Tiki/platnet.h" -#include "Tiki/net/tcpserversocket.h" +#include "Tiki/net.h" namespace Tiki { Modified: tiki/src/net/tcpsocket.cpp =================================================================== --- tiki/src/net/tcpsocket.cpp 2007-08-21 04:08:54 UTC (rev 475) +++ tiki/src/net/tcpsocket.cpp 2007-08-21 04:24:11 UTC (rev 476) @@ -8,7 +8,7 @@ #include "pch.h" #include "Tiki/tiki.h" -#include "Tiki/platnet.h" +#include "Tiki/net.h" #include <errno.h> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-21 04:09:25
|
Revision: 475 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=475&view=rev Author: atani Date: 2007-08-20 21:08:54 -0700 (Mon, 20 Aug 2007) Log Message: ----------- Initial cut of Tiki::Net support currently implemented: * Address resolution (win32, sdl, OSX maybe [needs testing]) * basic TCPSocket support (connect, disconnect, read, write) for sdl, win32, partial OSX support * example of connecting to http://www.example.com/ and downloading index.html Modified Paths: -------------- tiki/examples/TikiTest/TikiTest_vc80.vcproj tiki/examples/console/TikiSnake/TikiSnake.vcproj tiki/osx/src/init_shutdown.cpp tiki/sdl/Makefile tiki/sdl/src/init_shutdown.cpp tiki/win32/tiki_vc80.sln tiki/win32/tiki_vs80.vcproj Added Paths: ----------- tiki/examples/net/ tiki/examples/net/basic/ tiki/examples/net/basic/Makefile tiki/examples/net/basic/basic.vcproj tiki/examples/net/basic/src/ tiki/examples/net/basic/src/BasicNetTest.cpp tiki/examples/net/basic/src/main.cpp tiki/include/Tiki/net/ tiki/include/Tiki/net/address.h tiki/include/Tiki/net/buffer.h tiki/include/Tiki/net/net.h tiki/include/Tiki/net/socket.h tiki/include/Tiki/net/tcpserversocket.h tiki/include/Tiki/net/tcpsocket.h tiki/include/Tiki/net/udpsocket.h tiki/osx/include/Tiki/platnet.h tiki/osx/src/platnet.cpp tiki/sdl/include/Tiki/platnet.h tiki/sdl/src/platnet.cpp tiki/src/net/ tiki/src/net/address.cpp tiki/src/net/socket.cpp tiki/src/net/tcpserversocket.cpp tiki/src/net/tcpsocket.cpp tiki/win32/include/Tiki/platnet.h tiki/win32/src/platnet.cpp Modified: tiki/examples/TikiTest/TikiTest_vc80.vcproj =================================================================== --- tiki/examples/TikiTest/TikiTest_vc80.vcproj 2007-08-16 23:06:56 UTC (rev 474) +++ tiki/examples/TikiTest/TikiTest_vc80.vcproj 2007-08-21 04:08:54 UTC (rev 475) @@ -59,7 +59,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib" + AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib ws2_32.lib" LinkIncremental="2" AdditionalLibraryDirectories="$(ProjectDir)\..\..\win32\Debug;"C:\Program Files\OpenAL 1.1 SDK\libs\Win32"" GenerateDebugInformation="true" @@ -134,7 +134,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib" + AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib ws2_32.lib" LinkIncremental="1" AdditionalLibraryDirectories="$(ProjectDir)\..\..\win32\Release;C:\Program Files\OpenAL 1.1 SDK\libs\Win32" IgnoreDefaultLibraryNames="" Modified: tiki/examples/console/TikiSnake/TikiSnake.vcproj =================================================================== --- tiki/examples/console/TikiSnake/TikiSnake.vcproj 2007-08-16 23:06:56 UTC (rev 474) +++ tiki/examples/console/TikiSnake/TikiSnake.vcproj 2007-08-21 04:08:54 UTC (rev 475) @@ -59,7 +59,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib" + AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib ws2_32.lib" LinkIncremental="2" AdditionalLibraryDirectories="$(ProjectDir)\..\..\..\win32\Debug;"C:\Program Files\OpenAL 1.1 SDK\libs\Win32"" GenerateDebugInformation="true" @@ -134,7 +134,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib" + AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib ws2_32.lib" LinkIncremental="1" AdditionalLibraryDirectories="$(ProjectDir)\..\..\..\win32\Release;C:\Program Files\OpenAL 1.1 SDK\libs\Win32" IgnoreDefaultLibraryNames="" Added: tiki/examples/net/basic/Makefile =================================================================== --- tiki/examples/net/basic/Makefile (rev 0) +++ tiki/examples/net/basic/Makefile 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,13 @@ + +TIKI_DIR=../../../ +CFLAGS=-I$(TIKI_DIR)$(TIKI_PLAT)/include -I$(TIKI_DIR)include +OBJS = $(patsubst %.cpp,%.o,$(wildcard src/*.cpp)) + +all: $(OBJS) + $(CXX) $(LDFLAGS) -L$(TIKI_DIR)$(TIKI_PLAT) -L$(TIKI_DIR)$(TIKI_PLAT)/lib $(OBJS) $(TIKI_BASE_LIBS) -o basic + +clean: + -rm -f $(OBJS) basic + +DEPSDIR=$(CURDIR) +include $(TIKI_DIR)$(TIKI_PLAT)/Makefile.rules Added: tiki/examples/net/basic/basic.vcproj =================================================================== --- tiki/examples/net/basic/basic.vcproj (rev 0) +++ tiki/examples/net/basic/basic.vcproj 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,205 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="BasicNet" + ProjectGUID="{7B823C96-860C-4578-95CC-1087A45AF1AA}" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="Debug" + IntermediateDirectory="Debug" + ConfigurationType="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="$(ProjectDir)\..\..\..\win32\include;$(ProjectDir)\..\..\..\include;"C:\Program Files\OpenAL 1.1 SDK\include"" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib ws2_32.lib" + LinkIncremental="2" + AdditionalLibraryDirectories="$(ProjectDir)\..\..\..\win32\Debug;"C:\Program Files\OpenAL 1.1 SDK\libs\Win32"" + GenerateDebugInformation="true" + SubSystem="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="1" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="$(ProjectDir)\..\..\..\win32\include;$(ProjectDir)\..\..\..\include;"C:\Program Files\OpenAL 1.1 SDK\include"" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;" + RuntimeLibrary="0" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="gdi32.lib kernel32.lib user32.lib opengl32.lib glu32.lib comdlg32.lib ws2_32.lib" + LinkIncremental="1" + AdditionalLibraryDirectories="$(ProjectDir)\..\..\..\win32\Release;C:\Program Files\OpenAL 1.1 SDK\libs\Win32" + IgnoreDefaultLibraryNames="" + GenerateDebugInformation="true" + SubSystem="2" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" + > + </Filter> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\src\BasicNetTest.cpp" + > + </File> + <File + RelativePath=".\src\main.cpp" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Added: tiki/examples/net/basic/src/BasicNetTest.cpp =================================================================== --- tiki/examples/net/basic/src/BasicNetTest.cpp (rev 0) +++ tiki/examples/net/basic/src/BasicNetTest.cpp 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,27 @@ +/* +* Basic.cpp +* Basic Network test +* +* Copyright (C)2007 Atani Software +* +*/ + +#include <Tiki/tiki.h> +#include <pch.h> + +#if TIKI_PLAT == TIKI_WIN32 +#include <windows.h> + +static char szAppName[] = "BasicNetTest"; +int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) +#else +extern "C" int tiki_main( int argc, char *argv[] ); +int main( int argc, char *argv[] ) +#endif +{ +#if TIKI_PLAT != TIKI_WIN32 + return tiki_main( argc, argv ); +#else + return Tiki::DoMain( szAppName, hInst, hPrevInstance, lpCmdLine, nCmdShow ); +#endif +} Added: tiki/examples/net/basic/src/main.cpp =================================================================== --- tiki/examples/net/basic/src/main.cpp (rev 0) +++ tiki/examples/net/basic/src/main.cpp 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,55 @@ +/* +* Basic.cpp +* Basic Network test +* +* Copyright (C)2007 Atani Software +* +*/ + +#include <Tiki/tiki.h> +#include <Tiki/refcnt.h> +#include <Tiki/tikitime.h> +#include <Tiki/net/net.h> + +using namespace Tiki; +using namespace Tiki::Debug; +using namespace Tiki::Net; +using namespace Tiki::Net::TCP; +using namespace Tiki::Time; + +extern "C" int tiki_main( int argc, char **argv) { + + Tiki::Net::init(); + + RefPtr<Address> address = new Address(); + address->setHostName("www.example.com"); + address->setPort(80); + Tiki::Debug::printf("%s -> %s\n", + address->getHostName().c_str(), + address->getIPAddressString().c_str()); + + RefPtr<TCPSocket> socket = new TCPSocket(address); + + Tiki::Debug::printf("localaddress: %s\n", socket->getLocalAddress()->getIPAddressString().c_str()); + socket->open(); + + RefPtr<Buffer> buf = new Buffer(1024); + Tiki::Debug::printf("Requesting www.example.com/index.html"); + string str = "GET /index.html HTTP/1.1\r\nHost: " + address->getHostName() + "\r\n\r\n"; + buf->setData((uint8 *)str.c_str(), str.length()); + + socket->send(buf); + + Tiki::Time::sleep(50000); + + RefPtr<Buffer> reply = new Buffer(1024); + socket->recv(reply); + if(reply != NULL) { + Tiki::Debug::printf("%s\n", reply->getData()); + } + + socket->close(); + + Tiki::Net::shutdown(); + return 0; +} Added: tiki/include/Tiki/net/address.h =================================================================== --- tiki/include/Tiki/net/address.h (rev 0) +++ tiki/include/Tiki/net/address.h 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,55 @@ +/* + Tiki + + address.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_ADDRESS_H +#define __TIKI_NET_ADDRESS_H + +#include "Tiki/refcnt.h" + +namespace Tiki { + +namespace Net { + +class Address : public RefCnt +{ + public: + Address(); + + typedef enum AddressType { + AddressUnknown = 0x00000000, + AddressAny = 0x00000001, + AddressNone = 0x00000002, + AddressBroadcast = 0x00000003 + }; + + + int getPort() { + return m_port; + } + + void setPort(int port) { + m_port = port; + } + + string getHostName(); + void setHostName(string hostname); + + uint32 getIPAddress(); + string getIPAddressString(); + void setIPAddress(uint32 ip); + + private: + string m_hostname; + uint32 m_ip; + int m_port; +}; + +} // namespace Net + +} // namespace Tiki + +#endif // __TIKI_NET_ADDRESS_H Added: tiki/include/Tiki/net/buffer.h =================================================================== --- tiki/include/Tiki/net/buffer.h (rev 0) +++ tiki/include/Tiki/net/buffer.h 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,68 @@ +/* + Tiki + + buffer.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_BUFFER_H +#define __TIKI_NET_BUFFER_H + +#include "Tiki/object.h" + +namespace Tiki { + +namespace Net { + +class Buffer : public Object +{ + public: + Buffer(size_t len) { + m_data = new uint8[len]; + memset(m_data, 0, len); + m_dataLen = len; + } + Buffer(size_t len, uint8 *data) { + m_data = new uint8[len]; + memset(m_data, 0, len); + m_dataLen = len; + memcpy(m_data, data, len); + } + + uint8 *getData() const { + return m_data; + } + + size_t getDataLen() const { + return m_dataLen; + } + + size_t getUsedDataLen() const { + return m_usedDataLen; + } + + void setData(uint8 *data, size_t len) { + memset(m_data, 0, m_dataLen); + if(len > m_dataLen) + { + memcpy(m_data, data, m_dataLen); + m_usedDataLen = m_dataLen; + } + else + { + memcpy(m_data, data, len); + m_usedDataLen = len; + } + } + + private: + uint8 *m_data; + size_t m_dataLen; + size_t m_usedDataLen; +}; + +} // namespace Net + +} // namespace Tiki + +#endif // __TIKI_NET_UDPPACKET_H Added: tiki/include/Tiki/net/net.h =================================================================== --- tiki/include/Tiki/net/net.h (rev 0) +++ tiki/include/Tiki/net/net.h 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,28 @@ +/* + Tiki + + net.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_H +#define __TIKI_NET_H + +#include "Tiki/platnet.h" + +namespace Tiki { + +namespace Net { + +void init(); +void shutdown(); + +} // namespace Net + +} // namespace Tiki + +#endif // __TIKI_NET_H + +#include <Tiki/net/buffer.h> +#include <Tiki/net/address.h> +#include <Tiki/net/tcpsocket.h> Added: tiki/include/Tiki/net/socket.h =================================================================== --- tiki/include/Tiki/net/socket.h (rev 0) +++ tiki/include/Tiki/net/socket.h 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,79 @@ +/* + Tiki + + socket.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_SOCKET_H +#define __TIKI_NET_SOCKET_H + +#include "Tiki/object.h" +#include "Tiki/net/address.h" +#include "Tiki/net/buffer.h" + +namespace Tiki { + +namespace Net { + +class Socket : public Object +{ + public: + Socket(); + Socket(RefPtr<Address> address); + + RefPtr<Address> getPeerAddress() + { + return m_peerAddress; + } + + void setPeerAddress(RefPtr<Address> address) + { + m_peerAddress = address; + } + + RefPtr<Address> getLocalAddress() + { + return m_localAddress; + } + + bool isNonBlocking() + { + return m_blocking; + } + + void setNonBlocking(bool blocking) + { + m_blocking = blocking; + } + + bool isReuse() + { + return m_reuse; + } + + void setReuse(bool reuse) + { + m_reuse = reuse; + } + + virtual void send(RefPtr<Buffer> data) = 0; + + virtual void recv(RefPtr<Buffer> data) = 0; + + virtual void open() = 0; + + virtual void close() = 0; + + private: + RefPtr<Address> m_peerAddress; + RefPtr<Address> m_localAddress; + bool m_blocking; + bool m_reuse; +}; + +} // namespace Net + +} // namespace Tiki + +#endif // __TIKI_NET_SOCKET_H Added: tiki/include/Tiki/net/tcpserversocket.h =================================================================== --- tiki/include/Tiki/net/tcpserversocket.h (rev 0) +++ tiki/include/Tiki/net/tcpserversocket.h 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,36 @@ +/* + Tiki + + tcpservesocket.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_TCPSERVERSOCKET_H +#define __TIKI_NET_TCPSERVERSOCKET_H + +#include "Tiki/net/tcpsocket.h" + +namespace Tiki { + +namespace Net { + +namespace TCP { + +class TCPServerSocket : public TCPSocket +{ + public: + TCPServerSocket() : TCPSocket() {}; + TCPServerSocket(RefPtr<Address> address) : TCPSocket(address) {}; + + void bind(); + + RefPtr<TCPSocket> accept(); +}; + +} // namespace TCP + +} // namespace Net + +} // namespace Tiki + +#endif // __TIKI_NET_TCPSERVERSOCKET_H Added: tiki/include/Tiki/net/tcpsocket.h =================================================================== --- tiki/include/Tiki/net/tcpsocket.h (rev 0) +++ tiki/include/Tiki/net/tcpsocket.h 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,71 @@ +/* + Tiki + + tcpsocket.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_TCPSOCKET_H +#define __TIKI_NET_TCPSOCKET_H + +#include "Tiki/platnet.h" +#include "Tiki/net/buffer.h" +#include "Tiki/net/socket.h" + +namespace Tiki { + +namespace Net { + +namespace TCP { + +using Tiki::Net::Buffer; + +class TCPSocket : public Tiki::Net::Socket +{ + public: + +#ifndef INVALID_SOCKET + enum { + INVALID_SOCKET = -1, + SOCKET_ERROR = -1 + }; +#endif + TCPSocket() : Socket() {}; + TCPSocket(RefPtr<Address> address) : Socket(address) {}; + + virtual void send(RefPtr<Buffer> data); + + virtual void recv(RefPtr<Buffer> data); + + uint32 getPort() + { + return m_port; + } + + void setPort(uint32 port) + { + m_port = port; + } + virtual void open(); + + virtual void close(); + + private: + uint32 m_port; +#if TIKI_PLAT == TIKI_OSX + ; +#elif TIKI_PLAT == TIKI_WIN32 + SOCKET m_socket; +#else + int m_socket; +#endif + +}; + +} // namespace TCP + +} // namespace Net + +} // namespace Tiki + +#endif // __TIKI_NET_TCPSOCKET_H Added: tiki/include/Tiki/net/udpsocket.h =================================================================== --- tiki/include/Tiki/net/udpsocket.h (rev 0) +++ tiki/include/Tiki/net/udpsocket.h 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,36 @@ +/* + Tiki + + tcpsocket.h + + Copyright (C)2007 Atani Software +*/ +#ifndef __TIKI_NET_UDPSOCKET_H +#define __TIKI_NET_UDPSOCKET_H + +namespace Tiki { + +namespace Net { + +namespace UDP { + +#define MAX_UDP_CHANNELS 32 + +class UDPSocket : public Tiki::Net::Socket +{ + public: + virtual void send(RefPtr<Buffer> data); + virtual void recv(RefPtr<Buffer> data); + + void open(uint32 port); + + void bind(RefPtr<UDPSocket> socket, int channel, RefPtr<Address> address); +}; + +} // namespace UDP + +} // namespace Net + +} // namespace Tiki + +#endif // __TIKI_NET_UDPSOCKET_H Added: tiki/osx/include/Tiki/platnet.h =================================================================== --- tiki/osx/include/Tiki/platnet.h (rev 0) +++ tiki/osx/include/Tiki/platnet.h 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,33 @@ +/* + Tiki + + platnet.h + + Copyright (C)2007 Atani Software +*/ + +#ifndef TIKI_PLATFORM_NET_H +#define TIKI_PLATFORM_NET_H +#include <OpenTransport.h> +#include <OpenTptInternet.h> +#include <Events.h> + +namespace Tiki { + +namespace Net { + +enum DNS_STATUS { + NOT_READY = 0, + READY, + RESOLVED, + ERROR +}; + +extern DNS_STATUS g_tikiDNSStatus; +extern InetSvcRef g_tikiDNSRef; + +}; // namespace Net + +}; // namespace Tiki + +#endif // TIKI_PLATFORM_NET_H Modified: tiki/osx/src/init_shutdown.cpp =================================================================== --- tiki/osx/src/init_shutdown.cpp 2007-08-16 23:06:56 UTC (rev 474) +++ tiki/osx/src/init_shutdown.cpp 2007-08-21 04:08:54 UTC (rev 475) @@ -71,4 +71,5 @@ } }; + }; Added: tiki/osx/src/platnet.cpp =================================================================== --- tiki/osx/src/platnet.cpp (rev 0) +++ tiki/osx/src/platnet.cpp 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,82 @@ +/* + Tiki + + platnet.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "Tiki/tiki.h" +#include "Tiki/net/net.h" + +namespace Tiki { + +namespace Net { + +DNS_STATUS g_tikiDNSStatus; +InetSvcRef g_tikiDNSRef; + +static pascal void dnsNotifier(void *context, OTEventCode code, OTResult result, void *cookie) { + switch(code) { + case T_OPENCOMPLETE: + if(result == kOTNoError) { + g_tikiDNSStatus = READY; + g_tikiDNSRef = (InetSvcRef)cookie; + } + else { + g_tikiDNSStatus = ERROR; + Tiki::Debug::printf("T_DNRSTRINGTOADDRCOMPLETE event returned an error\n"); + } + break; + case T_DNRSTRINGTOADDRCOMPLETE: + g_tikiDNSStatus = RESOLVED; + break; + default: + if(result != kOTNoError) { + g_tikiDNSStatus = ERROR; + Tiki::Debug::printf("Error in DNS Resolver\n"); + } + } +} + +void startDNS() { + OSStatus status; + + status = OTAsyncOpenInternetServices( + kDefaultInternetServicesPath, 0, dnsNotifier, NULL); + if(status != noErr) { + Tiki::Debug::printf("Unable to initialize DNS Handler\n"); + } +} + +void stopDNS() { + if(g_dnsRef != 0) { + OTCloseProvider(g_tikiDNSRef); + g_tikiDNSStatus = NOT_READY; + g_tikiDNSRef = 0; + } +} + +void init() { + OSStatus status; + + g_tikiDNSStatus = NOT_READY; + g_tikiDNSRef = 0; + + status = InitOpenTransport(); + if(status == noErr) { + StartDNS(); + } + else { + Tiki::Debug::printf("Unable to initialize OpenTransport\n"); + } +} + +void shutdown() { + stopDNS(); +} + + +} + +}; Modified: tiki/sdl/Makefile =================================================================== --- tiki/sdl/Makefile 2007-08-16 23:06:56 UTC (rev 474) +++ tiki/sdl/Makefile 2007-08-21 04:08:54 UTC (rev 475) @@ -10,6 +10,7 @@ BASE_IMAGE_OBJ=$(patsubst %.cpp,%.o,$(wildcard ../src/image/*.cpp)) BASE_MATH_OBJ=$(patsubst %.cpp,%.o,$(wildcard ../src/math/*.cpp)) BASE_THREAD_OBJ=$(patsubst %.cpp,%.o,$(wildcard ../src/thread/*.cpp)) +BASE_NET_OBJ=$(patsubst %.cpp,%.o,$(wildcard ../src/net/*.cpp)) JPEG_OBJ=$(patsubst %.c,%.o,$(wildcard ../3rdparty/libjpeg/*.c)) PNG_OBJ=$(patsubst %.c,%.o,$(wildcard ../3rdparty/libpng/*.c)) @@ -39,7 +40,7 @@ BASE_OBJS = $(BASE_AUDIO_OBJ) $(BASE_BASE_OBJ) $(BASE_GL_OBJ) \ $(BASE_HID_OBJ) $(BASE_IMAGE_OBJ) $(BASE_MATH_OBJ) \ - $(BASE_THREAD_OBJ) + $(BASE_THREAD_OBJ) $(BASE_NET_OBJ) THIRD_PARTY_OBJS = $(JPEG_OBJ) $(OGG_OBJ) $(VORBIS_OBJ) $(PNG_OBJ) $(ZLIB_OBJ) Added: tiki/sdl/include/Tiki/platnet.h =================================================================== --- tiki/sdl/include/Tiki/platnet.h (rev 0) +++ tiki/sdl/include/Tiki/platnet.h 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,12 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <netinet/in.h> +#include <netinet/tcp.h> +#include <netdb.h> +#include <sys/socket.h> +#include <sys/time.h> + Modified: tiki/sdl/src/init_shutdown.cpp =================================================================== --- tiki/sdl/src/init_shutdown.cpp 2007-08-16 23:06:56 UTC (rev 474) +++ tiki/sdl/src/init_shutdown.cpp 2007-08-21 04:08:54 UTC (rev 475) @@ -59,4 +59,15 @@ } } +namespace Net { + +void init() +{ } + +void shutdown() +{ +} +} + +} Added: tiki/sdl/src/platnet.cpp =================================================================== --- tiki/sdl/src/platnet.cpp (rev 0) +++ tiki/sdl/src/platnet.cpp 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,26 @@ +/* + Tiki + + platnet.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "Tiki/tiki.h" +#include "Tiki/net/net.h" + +namespace Tiki { + +namespace Net { + +void init() +{ +} + +void shutdown() +{ +} + +} // namespace Net + +} // namespace Tiki Added: tiki/src/net/address.cpp =================================================================== --- tiki/src/net/address.cpp (rev 0) +++ tiki/src/net/address.cpp 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,129 @@ +/* + Tiki + + address.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "pch.h" +#include "Tiki/tiki.h" +#include "Tiki/platnet.h" +#include "Tiki/net/address.h" + +#include <sstream> + +namespace Tiki { + +namespace Net { + +Address::Address() +{ + m_hostname = ""; + m_ip = AddressUnknown; + m_port = 0; +} + +string Address::getHostName() +{ + if(m_hostname.empty() && + m_ip != AddressUnknown && + m_ip != AddressBroadcast && + m_ip != AddressAny && + m_ip != AddressNone ) + { +#if TIKI_PLAT == TIKI_OSX + InetHost ip; + InetDomainName domainName; + OSStatus status; + + domainName[0] = '\0'; + ip = m_ip; + status = OTInetAddressToName(g_tikiDNSRef, ip, domainName); + if(status == kOTNoError) { + while(g_tikiDNSStatus != RESOLVED) + { + ; + } + return domainName; + } +#else + struct hostent *hp = gethostbyaddr((char *)&m_ip, 4, AF_INET); + if(hp != NULL) + { + m_hostname = string(hp->h_name); + } +#endif + } + + return m_hostname; +} + +void Address::setHostName(string hostname) +{ + m_hostname = hostname; + m_ip = AddressUnknown; +} + +uint32 Address::getIPAddress() +{ + if(m_ip == AddressUnknown) + { + Tiki::Debug::printf("resolving host: %s\n", m_hostname.c_str()); +#if TIKI_PLAT == TIKI_OSX + InetHostInfo host; + if(OTInetStringToAddress(g_tikiDNSRef, m_hostname.c_str(), &info) == noErr) { + while( g_tikiDNSStatus != RESOLVED) + { + WaitNextEvent(everyEvent, 0, 1, NULL); + } + return info.addrs[0]; + } +#else + struct hostent *hp = gethostbyname(m_hostname.c_str()); + if(hp != NULL) + { + memcpy(&m_ip, hp->h_addr, hp->h_length); + } +#endif + } + return m_ip; +} + +string Address::getIPAddressString() +{ + if(m_ip == AddressAny) + { + return "0.0.0.0"; + } + else if(m_ip == AddressBroadcast || m_ip == AddressNone) + { + return "255.255.255.255"; + } + + uint32 ipnums = getIPAddress(); + uint8 *ip = (uint8 *)(&ipnums); + //Tiki::Debug::printf("host ip: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]); + + std::ostringstream address; + + address << (int)ip[0]; + address << "."; + address << (int)ip[1]; + address << "."; + address << (int)ip[2]; + address << "."; + address << (int)ip[3]; + + return address.str(); +} + +void Address::setIPAddress(uint32 ip) +{ + m_ip = ip; + m_hostname = ""; +} + +} // namespace Net + +} // namespace Tiki Added: tiki/src/net/socket.cpp =================================================================== --- tiki/src/net/socket.cpp (rev 0) +++ tiki/src/net/socket.cpp 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,37 @@ +/* + Tiki + + socket.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "pch.h" +#include "Tiki/tiki.h" +#include "Tiki/platnet.h" +#include "Tiki/net/socket.h" + +namespace Tiki { + +namespace Net { + +Socket::Socket() +{ + m_localAddress = new Address(); + m_localAddress->setHostName("localhost"); + m_blocking = true; + m_reuse = true; +} + +Socket::Socket(RefPtr<Address> address) +{ + m_peerAddress = address; + m_localAddress = new Address(); + m_localAddress->setHostName("localhost"); + m_blocking = true; + m_reuse = true; +} + +} // namespace Net + +} // namespace Tiki Added: tiki/src/net/tcpserversocket.cpp =================================================================== --- tiki/src/net/tcpserversocket.cpp (rev 0) +++ tiki/src/net/tcpserversocket.cpp 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,34 @@ +/* + Tiki + + tcpserversocket.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "pch.h" +#include "Tiki/tiki.h" +#include "Tiki/platnet.h" +#include "Tiki/net/tcpserversocket.h" + +namespace Tiki { + +namespace Net { + +namespace TCP { + +void TCPServerSocket::bind() +{ + +} + +RefPtr<TCPSocket> TCPServerSocket::accept() +{ + return NULL; +} + +} // namespace TCP + +} // namespace Net + +} // namespace Tiki Added: tiki/src/net/tcpsocket.cpp =================================================================== --- tiki/src/net/tcpsocket.cpp (rev 0) +++ tiki/src/net/tcpsocket.cpp 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,131 @@ +/* + Tiki + + tcpsocket.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "pch.h" +#include "Tiki/tiki.h" +#include "Tiki/platnet.h" + +#include <errno.h> + +namespace Tiki { + +namespace Net { + +namespace TCP { + +void TCPSocket::send(const RefPtr<Buffer> buffer) { +#if TIKI_PLAT == TIKI_OSX +#else + uint8 *data = buffer->getData(); + size_t dataLen = buffer->getUsedDataLen(); + int len; + + do { + Tiki::Debug::printf("sending %d bytes\n", dataLen); + len = ::send(m_socket, (const char *)data, (int)dataLen, 0); + if(len > 0) { + Tiki::Debug::printf("sent %d bytes\n", len); + dataLen -= len; + data += len; + } + else { + Tiki::Debug::printf("sent %d bytes\n", len); + } + } while(dataLen > 0 && (len > 0 || errno == EINTR)); + Tiki::Debug::printf("errno: %d [%x]\n", errno, errno); +#endif +} + +void TCPSocket::recv(RefPtr<Buffer> data) { +#if TIKI_PLAT == TIKI_OSX +#else + uint8 *tmp = new uint8[data->getDataLen()]; + memset(tmp, 0, data->getDataLen()); + int recvlen = 0; + errno = 0; + do { + Tiki::Debug::printf("receiving %d bytes\n", data->getDataLen()); + recvlen = ::recv(m_socket, (char *)tmp, (int)data->getDataLen(), 0); + } while(errno == EINTR && (recvlen < 0 && !isNonBlocking())); + Tiki::Debug::printf("received %d bytes\nerrno %d\n", recvlen, errno); + if(recvlen > 0) { + data->setData(tmp, recvlen); + } +#endif + delete [] tmp; +} + +void TCPSocket::open() { +#if TIKI_PLAT == TIKI_OSX +#else + struct sockaddr_in sock_addr; + m_socket = socket(AF_INET, SOCK_STREAM, 0); + if(m_socket == INVALID_SOCKET) { + Tiki::Debug::printf("Error opening socket\n"); + return; + } + int yes = 1; + +#if TIKI_PLAT != TIKI_WIN32 + if(isReuse()) { + Tiki::Debug::printf("setting reuse flag\n"); + setsockopt(m_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)); + } +#endif + + if(!(getLocalAddress()->getIPAddress() == Address::AddressAny || + getLocalAddress()->getIPAddress() == Address::AddressNone || + getLocalAddress()->getIPAddress() == Address::AddressBroadcast)) { + // connecting to remote address + memset(&sock_addr, 0, sizeof(struct sockaddr_in)); + sock_addr.sin_family = AF_INET; + sock_addr.sin_addr.s_addr = getPeerAddress()->getIPAddress(); + sock_addr.sin_port = htons(getPeerAddress()->getPort()); + Tiki::Debug::printf("connecting to peer [%s->%s]\n", getPeerAddress()->getHostName().c_str(), getPeerAddress()->getIPAddressString().c_str()); + if( ::connect( m_socket, (struct sockaddr *)&sock_addr, sizeof(struct sockaddr_in)) == SOCKET_ERROR) { + Tiki::Debug::printf("Error opening socket\n"); + close(); + return; + } + Tiki::Debug::printf("Connected..\n"); + } + + Tiki::Debug::printf("setting TCP_NODELAY\n"); + setsockopt(m_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&yes, sizeof(yes)); + + if(isNonBlocking()) { + Tiki::Debug::printf("setting NO BLOCKING mode\n"); +#if TIKI_PLAT == TIKI_WIN32 + unsigned long mode = 1; + ioctlsocket(m_socket, FIONBIO, &mode); +#else + fcntl(m_socket, F_SETFL, O_NONBLOCK); +#endif + } +#endif +} + +void TCPSocket::close() { + Tiki::Debug::printf("closing socket\n"); +#if TIKI_PLAT == TIKI_OSX +#elif TIKI_PLAT == TIKI_WIN32 + if(m_socket != INVALID_SOCKET) { + closesocket(m_socket); + } +#else + if(m_socket != INVALID_SOCKET) { + ::close(m_socket); + } +#endif +} + +} // namespace TCP + +} // namespace Net + +} // namespace Tiki Added: tiki/win32/include/Tiki/platnet.h =================================================================== --- tiki/win32/include/Tiki/platnet.h (rev 0) +++ tiki/win32/include/Tiki/platnet.h 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,6 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <fcntl.h> + +#include <winsock2.h> \ No newline at end of file Added: tiki/win32/src/platnet.cpp =================================================================== --- tiki/win32/src/platnet.cpp (rev 0) +++ tiki/win32/src/platnet.cpp 2007-08-21 04:08:54 UTC (rev 475) @@ -0,0 +1,39 @@ +/* + Tiki + + platnet.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "pch.h" +#include "Tiki/tiki.h" +#include "Tiki/net/net.h" + +namespace Tiki { + +namespace Net { + +void init() +{ + WORD version_wanted = MAKEWORD(1,1); + WSADATA wsaData; + + if ( WSAStartup(version_wanted, &wsaData) != 0 ) { + Tiki::Debug::printf("Couldn't initialize Winsock 1.1\n"); + } +} + +void shutdown() +{ + if ( WSACleanup() == SOCKET_ERROR ) { + if ( WSAGetLastError() == WSAEINPROGRESS ) { + WSACancelBlockingCall(); + WSACleanup(); + } + } +} + +} // namespace Net + +} // namespace Tiki \ No newline at end of file Modified: tiki/win32/tiki_vc80.sln =================================================================== --- tiki/win32/tiki_vc80.sln 2007-08-16 23:06:56 UTC (rev 474) +++ tiki/win32/tiki_vc80.sln 2007-08-21 04:08:54 UTC (rev 475) @@ -13,6 +13,11 @@ {F2816CAC-B560-4ED9-8A73-9635F832943C} = {F2816CAC-B560-4ED9-8A73-9635F832943C} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BasicNet", "..\examples\net\basic\basic.vcproj", "{7B823C96-860C-4578-95CC-1087A45AF1AA}" + ProjectSection(ProjectDependencies) = postProject + {F2816CAC-B560-4ED9-8A73-9635F832943C} = {F2816CAC-B560-4ED9-8A73-9635F832943C} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -31,6 +36,10 @@ {FCAE4EF3-7B5D-4C0D-8793-4157F7D8709F}.Debug|Win32.Build.0 = Debug|Win32 {FCAE4EF3-7B5D-4C0D-8793-4157F7D8709F}.Release|Win32.ActiveCfg = Release|Win32 {FCAE4EF3-7B5D-4C0D-8793-4157F7D8709F}.Release|Win32.Build.0 = Release|Win32 + {7B823C96-860C-4578-95CC-1087A45AF1AA}.Debug|Win32.ActiveCfg = Debug|Win32 + {7B823C96-860C-4578-95CC-1087A45AF1AA}.Debug|Win32.Build.0 = Debug|Win32 + {7B823C96-860C-4578-95CC-1087A45AF1AA}.Release|Win32.ActiveCfg = Release|Win32 + {7B823C96-860C-4578-95CC-1087A45AF1AA}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE Modified: tiki/win32/tiki_vs80.vcproj =================================================================== --- tiki/win32/tiki_vs80.vcproj 2007-08-16 23:06:56 UTC (rev 474) +++ tiki/win32/tiki_vs80.vcproj 2007-08-21 04:08:54 UTC (rev 475) @@ -396,6 +396,26 @@ > </File> </Filter> + <Filter + Name="net" + > + <File + RelativePath="..\src\net\address.cpp" + > + </File> + <File + RelativePath="..\src\net\socket.cpp" + > + </File> + <File + RelativePath="..\src\net\tcpserversocket.cpp" + > + </File> + <File + RelativePath="..\src\net\tcpsocket.cpp" + > + </File> + </Filter> </Filter> <Filter Name="Include" @@ -624,6 +644,38 @@ > </File> </Filter> + <Filter + Name="net" + > + <File + RelativePath="..\include\Tiki\net\address.h" + > + </File> + <File + RelativePath="..\include\Tiki\net\buffer.h" + > + </File> + <File + RelativePath="..\include\Tiki\net\net.h" + > + </File> + <File + RelativePath="..\include\Tiki\net\socket.h" + > + </File> + <File + RelativePath="..\include\Tiki\net\tcpserversocket.h" + > + </File> + <File + RelativePath="..\include\Tiki\net\tcpsocket.h" + > + </File> + <File + RelativePath="..\include\Tiki\net\udpsocket.h" + > + </File> + </Filter> </Filter> </Filter> <Filter @@ -653,6 +705,10 @@ > </File> <File + RelativePath=".\src\platnet.cpp" + > + </File> + <File RelativePath=".\src\platthread.cpp" > </File> @@ -695,6 +751,10 @@ > </File> <File + RelativePath=".\include\Tiki\platnet.h" + > + </File> + <File RelativePath=".\include\Tiki\platthread.h" > </File> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-16 23:06:59
|
Revision: 474 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=474&view=rev Author: atani Date: 2007-08-16 16:06:56 -0700 (Thu, 16 Aug 2007) Log Message: ----------- proper fix for assert in previous revisions Modified Paths: -------------- tiki/src/gl/drawables/console.cpp Modified: tiki/src/gl/drawables/console.cpp =================================================================== --- tiki/src/gl/drawables/console.cpp 2007-08-16 22:39:10 UTC (rev 473) +++ tiki/src/gl/drawables/console.cpp 2007-08-16 23:06:56 UTC (rev 474) @@ -1,12 +1,12 @@ /* - Tiki - - console.cpp - - Copyright (C)2001 - 2006 Sam Steele - Portions (C) Atani Software - */ +Tiki +console.cpp + +Copyright (C)2001 - 2006 Sam Steele +Portions (C) Atani Software +*/ + #include "pch.h" #include "Tiki/tiki.h" @@ -17,484 +17,556 @@ using namespace Tiki::GL; using namespace Tiki::GL::Plxcompat; -ConsoleText::ConsoleText(int cols, int rows, Texture * texture) { +ConsoleText::ConsoleText( int cols, int rows, Texture * texture ) +{ m_texture = texture; m_rows = rows; m_cols = cols; - m_palette[0] = Color(0,0,0); - m_palette[1] = Color(0,0,0.5); - m_palette[2] = Color(0,0.5,0); - m_palette[3] = Color(0,0.5,0.5); - m_palette[4] = Color(0.5,0,0); - m_palette[5] = Color(0.5,0,0.5); - m_palette[6] = Color(0.5,0.5,0); - m_palette[7] = Color(0.5,0.5,0.5); - - m_charData.resize(rows*cols, 0); - m_colorData.resize(rows*cols, 0); - + m_palette[ 0 ] = Color( 0, 0, 0 ); + m_palette[ 1 ] = Color( 0, 0, 0.5 ); + m_palette[ 2 ] = Color( 0, 0.5, 0 ); + m_palette[ 3 ] = Color( 0, 0.5, 0.5 ); + m_palette[ 4 ] = Color( 0.5, 0, 0 ); + m_palette[ 5 ] = Color( 0.5, 0, 0.5 ); + m_palette[ 6 ] = Color( 0.5, 0.5, 0 ); + m_palette[ 7 ] = Color( 0.5, 0.5, 0.5 ); + + m_charData.resize( rows * cols, 0 ); + m_colorData.resize( rows * cols, 0 ); + m_texture->select(); - + #if TIKI_PLAT != TIKI_DC && TIKI_PLAT != TIKI_NDS - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); #endif - + m_cursor_x = 0; m_cursor_y = 0; - + m_autoScroll = true; m_autoWrap = true; m_ansi = false; m_autoRefresh = false; - - color(GREY,BLACK); + + color( GREY, BLACK ); clear(); } -ConsoleText::~ConsoleText() { -} +ConsoleText::~ConsoleText() +{} -void ConsoleText::setTexture(Texture * txr) { +void ConsoleText::setTexture( Texture * txr ) +{ m_texture = txr; } -void ConsoleText::setSize(float w, float h) { +void ConsoleText::setSize( float w, float h ) +{ m_w = w; m_h = h; } -void ConsoleText::clear() { +void ConsoleText::clear() +{ int x; - - for(x=0; x<m_rows*m_cols; x++) { - m_charData[x] = 0; - m_colorData[x] = m_attr; + + for ( x = 0; x < m_rows*m_cols; x++ ) + { + m_charData[ x ] = 0; + m_colorData[ x ] = m_attr; } - + m_cursor_x = 0; m_cursor_y = 0; ansiptr = 0; - - if(m_autoRefresh) refresh(); + + if ( m_autoRefresh ) + refresh(); } -void ConsoleText::scroll(int rows, int top, int left, int bottom, int right) { - assert(top >= 0 && left >= 0 && bottom <= m_rows && right <= m_cols); - - for(int y=top; y<=bottom; y++) { - for(int x=left; x<=right; x++) { - if(y + rows < m_rows && y + rows >= 0) { - m_charData[(y * m_cols) + x] = m_charData[((y + rows) * m_cols) + x]; - m_colorData[(y * m_cols) + x] = m_colorData[((y + rows) * m_cols) + x]; - } else { - m_charData[(y * m_cols) + x] = 0; - m_colorData[(y * m_cols) + x] = m_attr; +void ConsoleText::scroll( int rows, int top, int left, int bottom, int right ) +{ + assert( top >= 0 && left >= 0 && bottom <= m_rows && right <= m_cols ); + + for ( int y = top; y <= bottom; y++ ) + { + for ( int x = left; x <= right; x++ ) + { + if ( y + rows < m_rows && y + rows >= 0 ) + { + m_charData[ ( y * m_cols ) + x ] = m_charData[ ( ( y + rows ) * m_cols ) + x ]; + m_colorData[ ( y * m_cols ) + x ] = m_colorData[ ( ( y + rows ) * m_cols ) + x ]; } + else + { + m_charData[ ( y * m_cols ) + x ] = 0; + m_colorData[ ( y * m_cols ) + x ] = m_attr; + } } } - - if(m_autoRefresh) refresh(); + + if ( m_autoRefresh ) + refresh(); } -void ConsoleText::scroll(int rows) { - scroll(rows,0,0,m_rows-1,m_cols-1); +void ConsoleText::scroll( int rows ) +{ + scroll( rows, 0, 0, m_rows - 1, m_cols - 1 ); } -void ConsoleText::locate(int x, int y) { +void ConsoleText::locate( int x, int y ) +{ m_cursor_x = x; m_cursor_y = y; } -void ConsoleText::color(int fg, int bg) { +void ConsoleText::color( int fg, int bg ) +{ m_attr = 0x0000; - if(fg > 7 && fg <= 16) { //Old style high intensity + if ( fg > 7 && fg <= 16 ) + { //Old style high intensity m_attr |= HIGH_INTENSITY; fg -= 8; } m_attr |= fg; - m_attr |= (bg << 8); + m_attr |= ( bg << 8 ); } -void ConsoleText::printf(const char *fmt, ...) { - char buf[1024]; +void ConsoleText::printf( const char *fmt, ... ) +{ + char buf[ 1024 ]; va_list args; - - va_start(args,fmt); - vsprintf(buf,fmt,args); - va_end(args); - for(size_t i=0; i<strlen(buf); i++) { - if(m_cursor_x >= m_cols && m_autoWrap) { - m_cursor_y++; - m_cursor_x = 0; + va_start( args, fmt ); + vsprintf( buf, fmt, args ); + va_end( args ); + + for ( size_t i = 0; i < strlen( buf ); i++ ) + { + if ( ansiptr ) + { + if ( ansiptr > 50 ) + { + ansiptr = 0; + } + ansistr[ ansiptr++ ] = buf[ i ]; + ansistr[ ansiptr ] = 0; + if ( !isdigit( buf[ i ] ) && ( ( buf[ i ] != '[' ) && ( buf[ i ] != ';' ) ) ) + { + processAnsiString(); + } } - - if(m_cursor_y >= m_rows && m_autoScroll) { - scroll(1); - m_cursor_y = m_rows - 1; + else if ( buf[ i ] == '\x1b' && m_ansi ) + { + ansistr[ 0 ] = buf[ i ]; + ansiptr = 1; + ansistr[ ansiptr ] = 0; } + else + { + if ( buf[ i ] == '\n' ) + { + m_cursor_y++; + m_cursor_x = 0; + continue; + } + else if ( buf[ i ] == '\r' ) + { + m_cursor_x = 0; + continue; + } + else if ( buf[ i ] == '\b' ) + { + m_cursor_x--; + if ( m_cursor_x < 0 ) + m_cursor_x = 0; + continue; + } + else if ( buf[ i ] == 12 ) + { // funky old style clearscreen + clear(); + continue; + } + if ( m_cursor_x >= m_cols && m_autoWrap ) + { + m_cursor_y++; + m_cursor_x = 0; + } - if(ansiptr) { - if(ansiptr > 50) { - ansiptr = 0; - } - ansistr[ansiptr++] = buf[i]; - ansistr[ansiptr] = 0; - if(!isdigit(buf[i]) && ((buf[i] != '[') && (buf[i] != ';'))) { - processAnsiString(); - } - } else if(buf[i] == '\x1b' && m_ansi) { - ansistr[0] = buf[i]; - ansiptr = 1; - ansistr[ansiptr] = 0; - } else { - if(buf[i] == '\n') { - m_cursor_y++; - m_cursor_x=0; - continue; - } else if(buf[i] == '\r') { - m_cursor_x = 0; - continue; - } else if(buf[i] == '\b') { - m_cursor_x--; - if(m_cursor_x < 0) m_cursor_x = 0; - continue; - } else if(buf[i] == 12) { // funky old style clearscreen - clear(); - continue; - } - - assert(m_cursor_x >= 0 && m_cursor_y >= 0 && m_cursor_x <= m_cols && m_cursor_y <= m_rows); - - m_charData[(m_cursor_y * m_cols) + m_cursor_x] = buf[i]; - m_colorData[(m_cursor_y * m_cols) + m_cursor_x] = m_attr; - + if ( m_cursor_y >= m_rows && m_autoScroll ) + { + scroll( 1 ); + m_cursor_y = m_rows - 1; + } + + + assert( m_cursor_x >= 0 && m_cursor_y >= 0 && m_cursor_x < m_cols && m_cursor_y < m_rows ); + + m_charData[ ( m_cursor_y * m_cols ) + m_cursor_x ] = buf[ i ]; + m_colorData[ ( m_cursor_y * m_cols ) + m_cursor_x ] = m_attr; + m_cursor_x++; - } + } } - - if(m_autoRefresh) refresh(); + + if ( m_autoRefresh ) + refresh(); } -void ConsoleText::renderCharacter(float x, float y, float w, float h, unsigned char c, int attr) { +void ConsoleText::renderCharacter( float x, float y, float w, float h, unsigned char c, int attr ) +{ plx_vertex_t vert; - float u = static_cast<float>((c % 16) * 8); - float v = static_cast<float>((c / 16) * 8); + float u = static_cast<float>( ( c % 16 ) * 8 ); + float v = static_cast<float>( ( c / 16 ) * 8 ); int color = attr & 0x07; - - + + const Vector & sv = getScale(); w *= sv.x; h *= sv.y; - - const Vector & tv = getPosition() + Vector(x, y, 0.01f); + const Vector & tv = getPosition() + Vector( x, y, 0.01f ); + m_texture->select(); - if(attr & HIGH_INTENSITY) { - vert.argb = Color(0.25, 0.25, 0.25); + if ( attr & HIGH_INTENSITY ) + { + vert.argb = Color( 0.25, 0.25, 0.25 ); //color -= 8; - } else { - vert.argb = Color(0,0,0); } - vert.argb += m_palette[color]; + else + { + vert.argb = Color( 0, 0, 0 ); + } + vert.argb += m_palette[ color ]; vert.oargb = 0; - + vert.flags = PLX_VERT; - vert.x = tv.x-m_w/2; - vert.y = tv.y+h-m_h/2; + vert.x = tv.x - m_w / 2; + vert.y = tv.y + h - m_h / 2; vert.z = tv.z; - vert.u = u/m_texture->getW(); - vert.v = (v+8)/m_texture->getH(); - plx_prim(&vert, sizeof(vert)); - - vert.y = tv.y-m_h/2; - vert.u = u/m_texture->getH(); - vert.v = v/m_texture->getW(); - plx_prim(&vert, sizeof(vert)); - - vert.x = tv.x+w-m_w/2; - vert.y = tv.y+h-m_h/2; - vert.u = (u+8)/m_texture->getW(); - vert.v = (v+8)/m_texture->getH(); - plx_prim(&vert, sizeof(vert)); - + vert.u = u / m_texture->getW(); + vert.v = ( v + 8 ) / m_texture->getH(); + plx_prim( &vert, sizeof( vert ) ); + + vert.y = tv.y - m_h / 2; + vert.u = u / m_texture->getH(); + vert.v = v / m_texture->getW(); + plx_prim( &vert, sizeof( vert ) ); + + vert.x = tv.x + w - m_w / 2; + vert.y = tv.y + h - m_h / 2; + vert.u = ( u + 8 ) / m_texture->getW(); + vert.v = ( v + 8 ) / m_texture->getH(); + plx_prim( &vert, sizeof( vert ) ); + vert.flags = PLX_VERT_EOS; - vert.y = tv.y-m_h/2; - vert.u = (u+8)/m_texture->getW(); - vert.v = v/m_texture->getH(); - plx_prim(&vert, sizeof(vert)); + vert.y = tv.y - m_h / 2; + vert.u = ( u + 8 ) / m_texture->getW(); + vert.v = v / m_texture->getH(); + plx_prim( &vert, sizeof( vert ) ); } -void ConsoleText::renderBackground(float x, float y, float w, float h, int color) { +void ConsoleText::renderBackground( float x, float y, float w, float h, int color ) +{ plx_vertex_t vert; const Vector & sv = getScale(); w *= sv.x; h *= sv.y; - - const Vector & tv = getPosition() + Vector(x, y, -0.01f); - + + const Vector & tv = getPosition() + Vector( x, y, -0.01f ); + m_texture->deselect(); - - vert.argb = m_palette[color]; + + vert.argb = m_palette[ color ]; vert.oargb = 0; - + vert.flags = PLX_VERT; - vert.x = tv.x-m_w/2; - vert.y = tv.y+h-m_h/2; + vert.x = tv.x - m_w / 2; + vert.y = tv.y + h - m_h / 2; vert.z = tv.z; - plx_prim(&vert, sizeof(vert)); - - vert.y = tv.y-m_h/2; - plx_prim(&vert, sizeof(vert)); - - vert.x = tv.x+w-m_w/2; - vert.y = tv.y+h-m_h/2; - plx_prim(&vert, sizeof(vert)); - + plx_prim( &vert, sizeof( vert ) ); + + vert.y = tv.y - m_h / 2; + plx_prim( &vert, sizeof( vert ) ); + + vert.x = tv.x + w - m_w / 2; + vert.y = tv.y + h - m_h / 2; + plx_prim( &vert, sizeof( vert ) ); + vert.flags = PLX_VERT_EOS; - vert.y = tv.y-m_h/2; - plx_prim(&vert, sizeof(vert)); + vert.y = tv.y - m_h / 2; + plx_prim( &vert, sizeof( vert ) ); } -void ConsoleText::draw(ObjType list) { - int x=0,y=0; - float x_step=(m_w / m_cols); - float y_step=(m_h / m_rows); +void ConsoleText::draw( ObjType list ) +{ + int x = 0, y = 0; + float x_step = ( m_w / m_cols ); + float y_step = ( m_h / m_rows ); #if TIKI_PLAT != TIKI_NDS - glDisable(GL_DEPTH_TEST); + + glDisable( GL_DEPTH_TEST ); #endif - - for(y=0; y<m_rows; y++) { - for(x=0; x<m_cols; x++) { - if(list == Trans) { //Characters! - renderCharacter(x*x_step, y*y_step, x_step, y_step, m_charData[y*(m_cols) + x], m_colorData[y*(m_cols) + x]); - } else { //Background blocks! - renderBackground(x*x_step, y*y_step, x_step, y_step, (m_colorData[y*(m_cols) + x] >> 8) & 0x07); + + for ( y = 0; y < m_rows; y++ ) + { + for ( x = 0; x < m_cols; x++ ) + { + if ( list == Trans ) + { //Characters! + renderCharacter( x * x_step, y * y_step, x_step, y_step, m_charData[ y * ( m_cols ) + x ], m_colorData[ y * ( m_cols ) + x ] ); } + else + { //Background blocks! + renderBackground( x * x_step, y * y_step, x_step, y_step, ( m_colorData[ y * ( m_cols ) + x ] >> 8 ) & 0x07 ); + } } } } -void ConsoleText::processAnsiString() { - if(ansistr[1] == '[') - { - int args[11], argptr = 0, ptr = 2, tempptr = 0; - char cmd, temp[11]; - memset(&args, 0, sizeof(int) * 11); - cmd = ansistr[ansiptr - 1]; - ansistr[ansiptr - 1] = 0; - while((ansistr[ptr]) && ((argptr < 10) && (tempptr < 10))) - { - if(ansistr[ptr] == ';') - { - temp[tempptr] = 0; - tempptr = 0; - args[argptr++] = atoi(temp); - } - else - { - temp[tempptr++] = ansistr[ptr]; - } - ++ptr; - } - if(tempptr && (argptr < 10)) - { - temp[tempptr] = 0; - args[argptr++] = atoi(temp); - } - if((cmd >= 'A') && (cmd <= 'D') && !args[0]) - { - args[0] = 1; - } - switch(cmd) - { - case 'f': - case 'H': // goto XY +void ConsoleText::processAnsiString() +{ + if ( ansistr[ 1 ] == '[' ) + { + int args[ 11 ], argptr = 0, ptr = 2, tempptr = 0; + char cmd, temp[ 11 ]; + memset( &args, 0, sizeof( int ) * 11 ); + cmd = ansistr[ ansiptr - 1 ]; + ansistr[ ansiptr - 1 ] = 0; + while ( ( ansistr[ ptr ] ) && ( ( argptr < 10 ) && ( tempptr < 10 ) ) ) + { + if ( ansistr[ ptr ] == ';' ) { - if(argptr == 0) + temp[ tempptr ] = 0; + tempptr = 0; + args[ argptr++ ] = atoi( temp ); + } + else + { + temp[ tempptr++ ] = ansistr[ ptr ]; + } + ++ptr; + } + if ( tempptr && ( argptr < 10 ) ) + { + temp[ tempptr ] = 0; + args[ argptr++ ] = atoi( temp ); + } + if ( ( cmd >= 'A' ) && ( cmd <= 'D' ) && !args[ 0 ] ) + { + args[ 0 ] = 1; + } + switch ( cmd ) + { + case 'f': + case 'H': // goto XY + { + if ( argptr == 0 ) { m_cursor_x = 0; m_cursor_y = 0; } else { - m_cursor_x = args[1]-1; - m_cursor_y = args[0]-1; + m_cursor_x = args[ 1 ] - 1; + m_cursor_y = args[ 0 ] - 1; } - if(m_cursor_x < 0) m_cursor_x = 0; - if(m_cursor_y < 0) m_cursor_y = 0; - if(m_cursor_x > m_cols - 1) m_cursor_x = m_cols - 1; - if(m_cursor_y > m_rows - 1) m_cursor_y = m_rows - 1; + if ( m_cursor_x < 0 ) + m_cursor_x = 0; + if ( m_cursor_y < 0 ) + m_cursor_y = 0; + if ( m_cursor_x > m_cols - 1 ) + m_cursor_x = m_cols - 1; + if ( m_cursor_y > m_rows - 1 ) + m_cursor_y = m_rows - 1; //printf("**** GOTO XY(%u,%u) ****\n", m_cursor_x, m_cursor_y); } - break; - case 'A': // UP * lines - m_cursor_y -= args[0]; - if(m_cursor_x < 0) m_cursor_x = 0; - if(m_cursor_y < 0) m_cursor_y = 0; - if(m_cursor_x > m_cols - 1) m_cursor_x = m_cols - 1; - if(m_cursor_y > m_rows - 1) m_cursor_y = m_rows - 1; - //printf("**** UP %u ****\n",m_cursor_y); - break; - case 'B': // DOWN * lines - m_cursor_y += args[0]; - if(m_cursor_x < 0) m_cursor_x = 0; - if(m_cursor_y < 0) m_cursor_y = 0; - if(m_cursor_x > m_cols - 1) m_cursor_x = m_cols - 1; - if(m_cursor_y > m_rows - 1) m_cursor_y = m_rows - 1; - //printf("**** DOWN %u ****\n",m_cursor_y); - break; - case 'C': // RIGHT * chars - m_cursor_x += args[0]; - if(m_cursor_x < 0) m_cursor_x = 0; - if(m_cursor_y < 0) m_cursor_y = 0; - if(m_cursor_x > m_cols - 1) m_cursor_x = m_cols - 1; - if(m_cursor_y > m_rows - 1) m_cursor_y = m_rows - 1; - //printf("**** RIGHT %u ****\n",m_cursor_y); - break; - case 'D': // LEFT * chars - m_cursor_x -= args[0]; - if(m_cursor_x < 0) m_cursor_x = 0; - if(m_cursor_y < 0) m_cursor_y = 0; - if(m_cursor_x > m_cols - 1) m_cursor_x = m_cols - 1; - if(m_cursor_y > m_rows - 1) m_cursor_y = m_rows - 1; - //printf("**** LEFT %u ****\n",m_cursor_y); - break; - case 'J': // clearscreen - clear(); - //printf("**** CLEAR SCREEN ****\n"); - break; - case 's': // save location - m_save_x = m_cursor_x; - m_save_y = m_cursor_y; - //printf("**** SAVE XY (%u, %u) ****\n", save_x, save_y); - break; - case 'u': // restore location - m_cursor_x = m_save_x; - m_cursor_y = m_save_y; - m_save_x = m_save_y = 0; - //printf("**** RESTORE XY (%u, %u) ****\n", m_cursor_x, m_cursor_y); - break; - case 'n': // ANSI detect - //remoteHost->write("\x1b[1;1R", 6); - //printf("**** ANSI DETECTION ****\n"); - break; - case 'k': - case 'K': // clear EOL + break; + case 'A': // UP * lines + m_cursor_y -= args[ 0 ]; + if ( m_cursor_x < 0 ) + m_cursor_x = 0; + if ( m_cursor_y < 0 ) + m_cursor_y = 0; + if ( m_cursor_x > m_cols - 1 ) + m_cursor_x = m_cols - 1; + if ( m_cursor_y > m_rows - 1 ) + m_cursor_y = m_rows - 1; + //printf("**** UP %u ****\n",m_cursor_y); + break; + case 'B': // DOWN * lines + m_cursor_y += args[ 0 ]; + if ( m_cursor_x < 0 ) + m_cursor_x = 0; + if ( m_cursor_y < 0 ) + m_cursor_y = 0; + if ( m_cursor_x > m_cols - 1 ) + m_cursor_x = m_cols - 1; + if ( m_cursor_y > m_rows - 1 ) + m_cursor_y = m_rows - 1; + //printf("**** DOWN %u ****\n",m_cursor_y); + break; + case 'C': // RIGHT * chars + m_cursor_x += args[ 0 ]; + if ( m_cursor_x < 0 ) + m_cursor_x = 0; + if ( m_cursor_y < 0 ) + m_cursor_y = 0; + if ( m_cursor_x > m_cols - 1 ) + m_cursor_x = m_cols - 1; + if ( m_cursor_y > m_rows - 1 ) + m_cursor_y = m_rows - 1; + //printf("**** RIGHT %u ****\n",m_cursor_y); + break; + case 'D': // LEFT * chars + m_cursor_x -= args[ 0 ]; + if ( m_cursor_x < 0 ) + m_cursor_x = 0; + if ( m_cursor_y < 0 ) + m_cursor_y = 0; + if ( m_cursor_x > m_cols - 1 ) + m_cursor_x = m_cols - 1; + if ( m_cursor_y > m_rows - 1 ) + m_cursor_y = m_rows - 1; + //printf("**** LEFT %u ****\n",m_cursor_y); + break; + case 'J': // clearscreen + clear(); + //printf("**** CLEAR SCREEN ****\n"); + break; + case 's': // save location + m_save_x = m_cursor_x; + m_save_y = m_cursor_y; + //printf("**** SAVE XY (%u, %u) ****\n", save_x, save_y); + break; + case 'u': // restore location + m_cursor_x = m_save_x; + m_cursor_y = m_save_y; + m_save_x = m_save_y = 0; + //printf("**** RESTORE XY (%u, %u) ****\n", m_cursor_x, m_cursor_y); + break; + case 'n': // ANSI detect + //remoteHost->write("\x1b[1;1R", 6); + //printf("**** ANSI DETECTION ****\n"); + break; + case 'k': + case 'K': // clear EOL { int x = m_cursor_x; - while(x < m_cols - 1) { - m_charData[(m_cursor_y * m_cols) + x] = 0; - m_colorData[(m_cursor_y * m_cols) + x++] = m_attr; - } + while ( x < m_cols - 1 ) + { + m_charData[ ( m_cursor_y * m_cols ) + x ] = 0; + m_colorData[ ( m_cursor_y * m_cols ) + x++ ] = m_attr; + } //printf("**** CLEAR EOL %u ****\n", m_cursor_y); } - break; - case 'm': // set color attribute, currently ignored + break; + case 'm': // set color attribute, currently ignored { //printf("**** SET ATTRIBUTE [%u]", argptr); int i; - for(i = 0; i < argptr; i++) + for ( i = 0; i < argptr; i++ ) { //printf(" %u", args[i]); - switch(args[i]) + switch ( args[ i ] ) { - case 0: - m_attr = 0x0007; // all normal - break; - case 1: - m_attr |= 0x1000; // bold (high intensity) - break; - case 4: - m_attr |= 0x2000; // underscore - break; - case 5: - m_attr |= 0x4000; // blink - break; - case 7: - m_attr |= 0x8000; // reverse video - break; - case 8: - m_attr |= 0xA000; // invisible - break; - case 30: // black fg - m_attr &= 0xFF00; - m_attr |= BLACK; - break; - case 31: // red fg - m_attr &= 0xFF00; - m_attr |= RED; - break; - case 32: // green fg - m_attr &= 0xFF00; - m_attr |= GREEN; - break; - case 33: // yellow fg - m_attr &= 0xFF00; - m_attr |= YELLOW; - break; - case 34: // blue fg - m_attr &= 0xFF00; - m_attr |= BLUE; - break; - case 35: // magenta fg - m_attr &= 0xFF00; - m_attr |= MAGENTA; - break; - case 36: // cyan fg - m_attr &= 0xFF00; - m_attr |= CYAN; - break; - case 37: // white fg - m_attr &= 0xFF00; - m_attr |= GREY; - break; - case 40: // black bg - m_attr &= 0xF0FF; - m_attr |= BLACK << 8; - break; - case 41: // red bg - m_attr &= 0xF0FF; - m_attr |= RED << 8; - break; - case 42: // green bg - m_attr &= 0xF0FF; - m_attr |= GREEN << 8; - break; - case 43: // yellow bg - m_attr &= 0xF0FF; - m_attr |= YELLOW << 8; - break; - case 44: // blue bg - m_attr &= 0xF0FF; - m_attr |= BLUE << 8; - break; - case 45: // magenta fg - m_attr &= 0xF0FF; - m_attr |= MAGENTA << 8; - break; - case 46: // cyan bg - m_attr &= 0xF0FF; - m_attr |= CYAN << 8; - break; - case 47: // white bg - m_attr &= 0xF0FF; - m_attr |= GREY << 8; - break; + case 0: + m_attr = 0x0007; // all normal + break; + case 1: + m_attr |= 0x1000; // bold (high intensity) + break; + case 4: + m_attr |= 0x2000; // underscore + break; + case 5: + m_attr |= 0x4000; // blink + break; + case 7: + m_attr |= 0x8000; // reverse video + break; + case 8: + m_attr |= 0xA000; // invisible + break; + case 30: // black fg + m_attr &= 0xFF00; + m_attr |= BLACK; + break; + case 31: // red fg + m_attr &= 0xFF00; + m_attr |= RED; + break; + case 32: // green fg + m_attr &= 0xFF00; + m_attr |= GREEN; + break; + case 33: // yellow fg + m_attr &= 0xFF00; + m_attr |= YELLOW; + break; + case 34: // blue fg + m_attr &= 0xFF00; + m_attr |= BLUE; + break; + case 35: // magenta fg + m_attr &= 0xFF00; + m_attr |= MAGENTA; + break; + case 36: // cyan fg + m_attr &= 0xFF00; + m_attr |= CYAN; + break; + case 37: // white fg + m_attr &= 0xFF00; + m_attr |= GREY; + break; + case 40: // black bg + m_attr &= 0xF0FF; + m_attr |= BLACK << 8; + break; + case 41: // red bg + m_attr &= 0xF0FF; + m_attr |= RED << 8; + break; + case 42: // green bg + m_attr &= 0xF0FF; + m_attr |= GREEN << 8; + break; + case 43: // yellow bg + m_attr &= 0xF0FF; + m_attr |= YELLOW << 8; + break; + case 44: // blue bg + m_attr &= 0xF0FF; + m_attr |= BLUE << 8; + break; + case 45: // magenta fg + m_attr &= 0xF0FF; + m_attr |= MAGENTA << 8; + break; + case 46: // cyan bg + m_attr &= 0xF0FF; + m_attr |= CYAN << 8; + break; + case 47: // white bg + m_attr &= 0xF0FF; + m_attr |= GREY << 8; + break; } } //printf(" ****\n"); } - break; - } - } + break; + } + } // else // { // printf("Bogus ANSI: %s\n", ansistr); // } - ansiptr = 0; + ansiptr = 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-16 22:39:11
|
Revision: 473 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=473&view=rev Author: atani Date: 2007-08-16 15:39:10 -0700 (Thu, 16 Aug 2007) Log Message: ----------- properly exclude .svn from tar files fix assert when ansi code goes over the 80x25 screen size (allows rendering to col 80) Modified Paths: -------------- tiki/gp2x/Makefile tiki/sdl/Makefile tiki/src/gl/drawables/console.cpp Modified: tiki/gp2x/Makefile =================================================================== --- tiki/gp2x/Makefile 2007-08-16 19:05:47 UTC (rev 472) +++ tiki/gp2x/Makefile 2007-08-16 22:39:10 UTC (rev 473) @@ -65,13 +65,14 @@ gp2x/include \ gp2x/lib \ gp2x/Makefile.rules \ - --exclude "*/.svn/*" + --exclude .svn cp ../examples/console/TikiSnake/resources/pc-ascii.png \ ../examples/console/TikiSnake tar -uvf ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-gp2x.tar -C ../ \ examples/TikiTest/tikitest \ examples/console/TikiSnake/tikisnake \ - examples/console/TikiSnake/pc-ascii.png --exclude "*/.svn/*" + examples/console/TikiSnake/pc-ascii.png \ + --exclude .svn rm -f ../examples/console/TikiSnake/pc-ascii.png gzip ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-gp2x.tar Modified: tiki/sdl/Makefile =================================================================== --- tiki/sdl/Makefile 2007-08-16 19:05:47 UTC (rev 472) +++ tiki/sdl/Makefile 2007-08-16 22:39:10 UTC (rev 473) @@ -64,13 +64,14 @@ include \ sdl/include \ sdl/Makefile.rules \ - --exclude "*/.svn/*" + --exclude .svn cp ../examples/console/TikiSnake/resources/pc-ascii.png \ ../examples/console/TikiSnake tar -uvf ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-sdl.tar -C ../ \ examples/TikiTest/tikitest \ examples/console/TikiSnake/tikisnake \ - examples/console/TikiSnake/pc-ascii.png --exclude "*/.svn/*" + examples/console/TikiSnake/pc-ascii.png \ + --exclude .svn rm -f ../examples/console/TikiSnake/pc-ascii.png gzip ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-sdl.tar Modified: tiki/src/gl/drawables/console.cpp =================================================================== --- tiki/src/gl/drawables/console.cpp 2007-08-16 19:05:47 UTC (rev 472) +++ tiki/src/gl/drawables/console.cpp 2007-08-16 22:39:10 UTC (rev 473) @@ -81,7 +81,7 @@ } void ConsoleText::scroll(int rows, int top, int left, int bottom, int right) { - assert(top >= 0 && left >= 0 && bottom < m_rows && right < m_cols); + assert(top >= 0 && left >= 0 && bottom <= m_rows && right <= m_cols); for(int y=top; y<=bottom; y++) { for(int x=left; x<=right; x++) { @@ -166,7 +166,7 @@ continue; } - assert(m_cursor_x >= 0 && m_cursor_y >= 0 && m_cursor_x < m_cols && m_cursor_y < m_rows); + assert(m_cursor_x >= 0 && m_cursor_y >= 0 && m_cursor_x <= m_cols && m_cursor_y <= m_rows); m_charData[(m_cursor_y * m_cols) + m_cursor_x] = buf[i]; m_colorData[(m_cursor_y * m_cols) + m_cursor_x] = m_attr; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-16 19:05:52
|
Revision: 472 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=472&view=rev Author: atani Date: 2007-08-16 12:05:47 -0700 (Thu, 16 Aug 2007) Log Message: ----------- check for Apple modified version of OpenAL which takes a "const ALCchar *" for alcOpenDevice Modified Paths: -------------- tiki/osx/src/init_shutdown.cpp Modified: tiki/osx/src/init_shutdown.cpp =================================================================== --- tiki/osx/src/init_shutdown.cpp 2007-08-16 18:46:17 UTC (rev 471) +++ tiki/osx/src/init_shutdown.cpp 2007-08-16 19:05:47 UTC (rev 472) @@ -31,8 +31,8 @@ bool init( int argc, char **argv ) { ALCdevice * dev = NULL; ALCcontext *ctx = NULL; -#if ALC_MAJOR_VERSION == 0x1000 && ALC_MINOR_VERSION == 0x1001 - dev = alcOpenDevice( (ALCubyte *)( getenv( "OPENAL_DEVICE" ) ) ); // getenv()==NULL is okay. +#if defined(ALC_VERSION_0_1) + dev = alcOpenDevice( const_cast<ALCchar *>( getenv( "OPENAL_DEVICE" ) ) ); // getenv()==NULL is okay. #else dev = alcOpenDevice( getenv( "OPENAL_DEVICE" ) ); // getenv()==NULL is okay. #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-16 18:46:21
|
Revision: 471 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=471&view=rev Author: atani Date: 2007-08-16 11:46:17 -0700 (Thu, 16 Aug 2007) Log Message: ----------- use "svn export" instead of cp for copying to Tiki.framework/PrivateHeaders check ALC_[MAJOR,MINOR]_VERSION fields before casting getenv return value, CoreAudioSDK 1.4.3 requires the cast Modified Paths: -------------- tiki/osx/Tiki.xcodeproj/project.pbxproj tiki/osx/src/init_shutdown.cpp Modified: tiki/osx/Tiki.xcodeproj/project.pbxproj =================================================================== --- tiki/osx/Tiki.xcodeproj/project.pbxproj 2007-08-16 17:22:51 UTC (rev 470) +++ tiki/osx/Tiki.xcodeproj/project.pbxproj 2007-08-16 18:46:17 UTC (rev 471) @@ -1045,7 +1045,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "HDRS=${BUILT_PRODUCTS_DIR}/${PRIVATE_HEADERS_FOLDER_PATH}\n\nif ! [ -e \"$HDRS\" ]; then mkdir \"$HDRS\"; fi\n\n#if [ -L \"$HDRS\"/boost ]; then rm -f \"$HDRS\"/boost; fi\n#ln -s ../../../../../../3rdparty/boost \"$HDRS\"\n\ncp -fpvR ../include/Tiki/* \"$HDRS\"\ncp -fpvR include/Tiki/* \"$HDRS\"\n"; + shellScript = "HDRS=${BUILT_PRODUCTS_DIR}/${PRIVATE_HEADERS_FOLDER_PATH}\n\nif ! [ -e \"$HDRS\" ]; then mkdir \"$HDRS\"; fi\n\nsvn export --force --non-interactive ../include/Tiki \"$HDRS\"\nsvn export --force --non-interactive include/Tiki \"$HDRS\"\n"; }; /* End PBXShellScriptBuildPhase section */ Modified: tiki/osx/src/init_shutdown.cpp =================================================================== --- tiki/osx/src/init_shutdown.cpp 2007-08-16 17:22:51 UTC (rev 470) +++ tiki/osx/src/init_shutdown.cpp 2007-08-16 18:46:17 UTC (rev 471) @@ -31,8 +31,12 @@ bool init( int argc, char **argv ) { ALCdevice * dev = NULL; ALCcontext *ctx = NULL; +#if ALC_MAJOR_VERSION == 0x1000 && ALC_MINOR_VERSION == 0x1001 + dev = alcOpenDevice( (ALCubyte *)( getenv( "OPENAL_DEVICE" ) ) ); // getenv()==NULL is okay. +#else + dev = alcOpenDevice( getenv( "OPENAL_DEVICE" ) ); // getenv()==NULL is okay. +#endif - dev = alcOpenDevice( (ALCubyte *)( getenv( "OPENAL_DEVICE" ) ) ); // getenv()==NULL is okay. if ( dev != NULL ) { ctx = alcCreateContext( dev, 0 ); if ( ctx != NULL ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-16 17:22:53
|
Revision: 470 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=470&view=rev Author: atani Date: 2007-08-16 10:22:51 -0700 (Thu, 16 Aug 2007) Log Message: ----------- adding typecast to prevent compilation failure on some machines Modified Paths: -------------- tiki/osx/src/init_shutdown.cpp Modified: tiki/osx/src/init_shutdown.cpp =================================================================== --- tiki/osx/src/init_shutdown.cpp 2007-08-15 23:27:51 UTC (rev 469) +++ tiki/osx/src/init_shutdown.cpp 2007-08-16 17:22:51 UTC (rev 470) @@ -32,7 +32,7 @@ ALCdevice * dev = NULL; ALCcontext *ctx = NULL; - dev = alcOpenDevice( getenv( "OPENAL_DEVICE" ) ); // getenv()==NULL is okay. + dev = alcOpenDevice( (ALCubyte *)( getenv( "OPENAL_DEVICE" ) ) ); // getenv()==NULL is okay. if ( dev != NULL ) { ctx = alcCreateContext( dev, 0 ); if ( ctx != NULL ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-15 23:27:53
|
Revision: 469 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=469&view=rev Author: atani Date: 2007-08-15 16:27:51 -0700 (Wed, 15 Aug 2007) Log Message: ----------- use - instead of ' ', tiki vs Tiki Modified Paths: -------------- tiki/osx/Makefile Modified: tiki/osx/Makefile =================================================================== --- tiki/osx/Makefile 2007-08-15 16:24:53 UTC (rev 468) +++ tiki/osx/Makefile 2007-08-15 23:27:51 UTC (rev 469) @@ -26,12 +26,12 @@ ../dist/$(SVN_VERSION)/tmp-debug/TikiSnake.app hdiutil create -fs HFS+ \ -srcfolder "../dist/$(SVN_VERSION)/tmp-debug" \ - -volname "Tiki r$(SVN_VERSION) Debug" \ - "../dist/$(SVN_VERSION)/Tiki-$(SVN_VERSION)-Debug.dmg" + -volname "Tiki-r$(SVN_VERSION)-Debug" \ + "../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-Debug.dmg" rm -rf ../dist/$(SVN_VERSION)/tmp-debug hdiutil internet-enable -yes \ - "../dist/$(SVN_VERSION)/Tiki-$(SVN_VERSION)-Debug.dmg" - gzip ../dist/$(SVN_VERSION)/Tiki-$(SVN_VERSION)-Debug.dmg + "../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-Debug.dmg" + gzip ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-Debug.dmg mkdir ../dist/$(SVN_VERSION)/tmp-release ditto -v build/Deployment/Tiki.framework \ ../dist/$(SVN_VERSION)/tmp-release/Tiki.framework @@ -41,9 +41,9 @@ ../dist/$(SVN_VERSION)/tmp-release/TikiSnake.app hdiutil create -fs HFS+ \ -srcfolder "../dist/$(SVN_VERSION)/tmp-release" \ - -volname "Tiki r$(SVN_VERSION) Release" \ - "../dist/$(SVN_VERSION)/Tiki-$(SVN_VERSION)-Release.dmg" + -volname "Tiki-r$(SVN_VERSION)-Release" \ + "../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-Release.dmg" hdiutil internet-enable -yes \ - "../dist/$(SVN_VERSION)/Tiki-$(SVN_VERSION)-Release.dmg" - gzip ../dist/$(SVN_VERSION)/Tiki-$(SVN_VERSION)-Release.dmg + "../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-Release.dmg" + gzip ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-Release.dmg rm -rf ../dist/$(SVN_VERSION)/tmp-release This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-15 16:24:56
|
Revision: 468 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=468&view=rev Author: atani Date: 2007-08-15 09:24:53 -0700 (Wed, 15 Aug 2007) Log Message: ----------- package gp2x/lib tree Modified Paths: -------------- tiki/gp2x/Makefile Modified: tiki/gp2x/Makefile =================================================================== --- tiki/gp2x/Makefile 2007-08-15 15:41:19 UTC (rev 467) +++ tiki/gp2x/Makefile 2007-08-15 16:24:53 UTC (rev 468) @@ -63,6 +63,7 @@ tar -uvf ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-gp2x.tar -C ../ \ include \ gp2x/include \ + gp2x/lib \ gp2x/Makefile.rules \ --exclude "*/.svn/*" cp ../examples/console/TikiSnake/resources/pc-ascii.png \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-15 15:41:29
|
Revision: 467 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=467&view=rev Author: atani Date: 2007-08-15 08:41:19 -0700 (Wed, 15 Aug 2007) Log Message: ----------- update packaging to include Makefile.rules where possible, gp2x -> tar.gz Modified Paths: -------------- tiki/dc/Makefile tiki/gp2x/Makefile tiki/nds/Makefile tiki/sdl/Makefile Modified: tiki/dc/Makefile =================================================================== --- tiki/dc/Makefile 2007-08-14 22:50:19 UTC (rev 466) +++ tiki/dc/Makefile 2007-08-15 15:41:19 UTC (rev 467) @@ -29,7 +29,16 @@ package: zip -9r ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-dc.zip libtiki.a - cd .. && zip -9ru dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-dc.zip include dc/include -x "*/.svn/*" - cd .. && zip -9ru dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-dc.zip examples/TikiTest/tikitest examples/console/TikiSnake/tikisnake -x "*/.svn/*" + cd .. && \ + zip -9ru dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-dc.zip \ + include \ + dc/include \ + dc/Makefile.rules \ + -x "*/.svn/*" + cd .. && \ + zip -9ru dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-dc.zip \ + examples/TikiTest/tikitest \ + examples/console/TikiSnake/tikisnake \ + -x "*/.svn/*" include Makefile.rules Modified: tiki/gp2x/Makefile =================================================================== --- tiki/gp2x/Makefile 2007-08-14 22:50:19 UTC (rev 466) +++ tiki/gp2x/Makefile 2007-08-15 15:41:19 UTC (rev 467) @@ -59,8 +59,19 @@ $(MAKE) TIKI_PLAT=gp2x TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/console/TikiSnake package: - zip -9r ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-gp2x.zip libtiki.a - cd .. && zip -9ru dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-gp2x.zip include gp2x/include -x "*/.svn/*" - cd .. && zip -9ru dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-gp2x.zip examples/TikiTest/tikitest examples/console/TikiSnake/tikisnake examples/console/TikiSnake/resources -x "*/.svn/*" + tar -cvf ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-gp2x.tar libtiki.a + tar -uvf ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-gp2x.tar -C ../ \ + include \ + gp2x/include \ + gp2x/Makefile.rules \ + --exclude "*/.svn/*" + cp ../examples/console/TikiSnake/resources/pc-ascii.png \ + ../examples/console/TikiSnake + tar -uvf ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-gp2x.tar -C ../ \ + examples/TikiTest/tikitest \ + examples/console/TikiSnake/tikisnake \ + examples/console/TikiSnake/pc-ascii.png --exclude "*/.svn/*" + rm -f ../examples/console/TikiSnake/pc-ascii.png + gzip ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-gp2x.tar include Makefile.rules Modified: tiki/nds/Makefile =================================================================== --- tiki/nds/Makefile 2007-08-14 22:50:19 UTC (rev 466) +++ tiki/nds/Makefile 2007-08-15 15:41:19 UTC (rev 467) @@ -58,9 +58,21 @@ $(MAKE) TIKI_PLAT=nds TIKI_DIR=$(CURDIR)/../ -C$(CURDIR)/../examples/console/TikiSnake package: - zip -9r ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-nds.zip libtiki.a arm7_template -x "*/.svn/*" - cd .. && zip -9ru dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-nds.zip include nds/include -x "*/.svn/*" - cd .. && zip -9ru dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-nds.zip examples/TikiTest/tikitest examples/console/TikiSnake/tikisnake -x "*/.svn/*" + zip -9r ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-nds.zip \ + libtiki.a \ + arm7_template \ + -x "*/.svn/*" + cd .. && \ + zip -9ru dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-nds.zip \ + include \ + nds/include \ + nds/Makefile.rules \ + -x "*/.svn/*" + cd .. && \ + zip -9ru dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-nds.zip \ + examples/TikiTest/tikitest \ + examples/console/TikiSnake/tikisnake \ + -x "*/.svn/*" DEPSDIR=$(CURDIR) TIKI_DIR=$(CURDIR)/.. Modified: tiki/sdl/Makefile =================================================================== --- tiki/sdl/Makefile 2007-08-14 22:50:19 UTC (rev 466) +++ tiki/sdl/Makefile 2007-08-15 15:41:19 UTC (rev 467) @@ -61,7 +61,10 @@ package: tar -cvf ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-sdl.tar libtiki.a tar -uvf ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-sdl.tar -C ../ \ - include sdl/include --exclude "*/.svn/*" + include \ + sdl/include \ + sdl/Makefile.rules \ + --exclude "*/.svn/*" cp ../examples/console/TikiSnake/resources/pc-ascii.png \ ../examples/console/TikiSnake tar -uvf ../dist/$(SVN_VERSION)/tiki-$(SVN_VERSION)-sdl.tar -C ../ \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <at...@us...> - 2007-08-14 22:50:21
|
Revision: 466 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=466&view=rev Author: atani Date: 2007-08-14 15:50:19 -0700 (Tue, 14 Aug 2007) Log Message: ----------- internet-enable dmg files to allow auto-mount Modified Paths: -------------- tiki/osx/Makefile Modified: tiki/osx/Makefile =================================================================== --- tiki/osx/Makefile 2007-08-14 22:44:13 UTC (rev 465) +++ tiki/osx/Makefile 2007-08-14 22:50:19 UTC (rev 466) @@ -29,6 +29,8 @@ -volname "Tiki r$(SVN_VERSION) Debug" \ "../dist/$(SVN_VERSION)/Tiki-$(SVN_VERSION)-Debug.dmg" rm -rf ../dist/$(SVN_VERSION)/tmp-debug + hdiutil internet-enable -yes \ + "../dist/$(SVN_VERSION)/Tiki-$(SVN_VERSION)-Debug.dmg" gzip ../dist/$(SVN_VERSION)/Tiki-$(SVN_VERSION)-Debug.dmg mkdir ../dist/$(SVN_VERSION)/tmp-release ditto -v build/Deployment/Tiki.framework \ @@ -41,5 +43,7 @@ -srcfolder "../dist/$(SVN_VERSION)/tmp-release" \ -volname "Tiki r$(SVN_VERSION) Release" \ "../dist/$(SVN_VERSION)/Tiki-$(SVN_VERSION)-Release.dmg" + hdiutil internet-enable -yes \ + "../dist/$(SVN_VERSION)/Tiki-$(SVN_VERSION)-Release.dmg" gzip ../dist/$(SVN_VERSION)/Tiki-$(SVN_VERSION)-Release.dmg rm -rf ../dist/$(SVN_VERSION)/tmp-release This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |