mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Add some missing GPL headers, fix building with Platform SDK 6.0, delete unused HTTP code.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@452 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -17,7 +17,11 @@
|
||||
#include <memory.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _interlockedbittestandset workaround_ms_header_bug_platform_sdk6_set
|
||||
#define _interlockedbittestandreset workaround_ms_header_bug_platform_sdk6_reset
|
||||
#include <intrin.h>
|
||||
#undef _interlockedbittestandset
|
||||
#undef _interlockedbittestandreset
|
||||
#else
|
||||
|
||||
//#include <config/i386/cpuid.h>
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#ifndef _DYNAMICLIBRARY_H
|
||||
#define _DYNAMICLIBRARY_H
|
||||
|
||||
|
@ -1,8 +1,29 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "Common.h"
|
||||
#include "FileUtil.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <shlobj.h> // for SHGetFolderPath
|
||||
#include <shellapi.h>
|
||||
#include <commdlg.h> // for GetSaveFileName
|
||||
#else
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
@ -85,17 +106,17 @@ bool File::CreateDir(const std::string &path)
|
||||
PanicAlert("Error creating directory: %i", error);
|
||||
return false;
|
||||
#else
|
||||
if (mkdir(path.c_str(), 0644) == 0)
|
||||
return true;
|
||||
if (mkdir(path.c_str(), 0644) == 0)
|
||||
return true;
|
||||
|
||||
int err = errno;
|
||||
int err = errno;
|
||||
|
||||
if (err == EEXIST) {
|
||||
PanicAlert("%s already exists", path.c_str());
|
||||
return true;
|
||||
}
|
||||
if (err == EEXIST) {
|
||||
PanicAlert("%s already exists", path.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
PanicAlert("Error creating directory: %s", strerror(err));
|
||||
PanicAlert("Error creating directory: %s", strerror(err));
|
||||
return false;
|
||||
|
||||
#endif
|
||||
@ -103,13 +124,16 @@ bool File::CreateDir(const std::string &path)
|
||||
|
||||
std::string GetUserDirectory() {
|
||||
#ifdef _WIN32
|
||||
//TODO
|
||||
return std::string("");
|
||||
char path[MAX_PATH];
|
||||
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, path)))
|
||||
{
|
||||
return std::string(path);
|
||||
}
|
||||
return std::string("");
|
||||
#else
|
||||
char *dir = getenv("HOME");
|
||||
if (!dir)
|
||||
return std::string("");
|
||||
|
||||
return dir;
|
||||
char *dir = getenv("HOME");
|
||||
if (!dir)
|
||||
return std::string("");
|
||||
return dir;
|
||||
#endif
|
||||
}
|
||||
|
@ -1,3 +1,20 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#ifndef _FILEUTIL_H
|
||||
#define _FILEUTIL_H
|
||||
|
||||
|
@ -1,309 +0,0 @@
|
||||
// Under MIT licence from http://www.mindcontrol.org/~hplus/http-get.html
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <time.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "HTTP.h"
|
||||
#include "PortableSockets.h"
|
||||
|
||||
#if !defined(WIN32)
|
||||
static int strnicmp( char const * a, char const * b, int n) {
|
||||
return strncasecmp( a, b, n );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
struct Chunk {
|
||||
Chunk() {
|
||||
next_ = 0;
|
||||
size_ = 0;
|
||||
}
|
||||
Chunk * next_;
|
||||
size_t size_;
|
||||
char data_[ 30000 ];
|
||||
};
|
||||
|
||||
class HTTPQuery : public I_HTTPRequest {
|
||||
public:
|
||||
HTTPQuery() {
|
||||
head_ = 0;
|
||||
curRd_ = 0;
|
||||
curWr_ = 0;
|
||||
curOffset_ = 0;
|
||||
toRead_ = 0;
|
||||
complete_ = false;
|
||||
gotLength_ = false;
|
||||
socket_ = BAD_SOCKET_FD;
|
||||
}
|
||||
~HTTPQuery() {
|
||||
if (socket_ != BAD_SOCKET_FD) {
|
||||
::closesocket( socket_ );
|
||||
}
|
||||
Chunk * ch = head_;
|
||||
while( ch != 0) {
|
||||
Chunk * d = ch;
|
||||
ch = ch->next_;
|
||||
::free( d );
|
||||
}
|
||||
}
|
||||
|
||||
void setQuery( char const * host, unsigned short port, char const * url) {
|
||||
if (strlen( url ) > 1536 || strlen( host ) > 256) {
|
||||
return;
|
||||
}
|
||||
struct hostent * hent = gethostbyname( host );
|
||||
if (hent == 0) {
|
||||
complete_ = true;
|
||||
return;
|
||||
}
|
||||
addr_.sin_family = AF_INET;
|
||||
addr_.sin_addr = *(in_addr *)hent->h_addr_list[0];
|
||||
addr_.sin_port = htons( port );
|
||||
socket_ = ::socket( AF_INET, SOCK_STREAM, getprotobyname("tcp")->p_proto );
|
||||
if (socket_ == BAD_SOCKET_FD) {
|
||||
complete_ = true;
|
||||
return;
|
||||
}
|
||||
int r;
|
||||
r = ::connect( socket_, (sockaddr *)&addr_, sizeof( addr_ ) );
|
||||
if (r < 0) {
|
||||
complete_ = true;
|
||||
return;
|
||||
}
|
||||
MAKE_SOCKET_NONBLOCKING( socket_, r );
|
||||
if (r < 0) {
|
||||
complete_ = true;
|
||||
return;
|
||||
}
|
||||
char buf[2048];
|
||||
sprintf( buf, "GET %s HTTP/1.0\r\nUser-Agent: Dolphin2.0\r\nAccept: */*\r\nHost: %s\r\nConnection: close\r\n\r\n",
|
||||
url, host );
|
||||
r = ::send( socket_, buf, int(strlen( buf )), NONBLOCK_MSG_SEND );
|
||||
if (r != (int)strlen( buf )) {
|
||||
complete_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
delete this;
|
||||
}
|
||||
void step() {
|
||||
if (!complete_) {
|
||||
if (!curWr_ || (curWr_->size_ == sizeof( curWr_->data_ ))) {
|
||||
Chunk * c = new Chunk;
|
||||
if (!head_) {
|
||||
head_ = c;
|
||||
curWr_ = c;
|
||||
}
|
||||
else {
|
||||
curWr_->next_ = c;
|
||||
curWr_ = c;
|
||||
}
|
||||
}
|
||||
assert( curWr_ && (curWr_->size_ < sizeof( curWr_->data_ )) );
|
||||
int r = ::recv( socket_, &curWr_->data_[curWr_->size_], int(sizeof(curWr_->data_)-curWr_->size_),
|
||||
NONBLOCK_MSG_SEND );
|
||||
if (r > 0) {
|
||||
curWr_->size_ += r;
|
||||
assert( curWr_->size_ <= sizeof( curWr_->data_ ) );
|
||||
if (gotLength_) {
|
||||
if (toRead_ <= size_t(r)) {
|
||||
toRead_ = 0;
|
||||
complete_ = true;
|
||||
}
|
||||
else {
|
||||
toRead_ -= r;
|
||||
}
|
||||
}
|
||||
if (!gotLength_) {
|
||||
char const * end = &head_->data_[head_->size_];
|
||||
char const * ptr = &head_->data_[1];
|
||||
while( ptr < end-1) {
|
||||
if (ptr[-1] == '\n') {
|
||||
if (!strnicmp( ptr, "content-length:", 15 )) {
|
||||
ptr += 15;
|
||||
toRead_ = strtol( ptr, (char **)&ptr, 10 );
|
||||
gotLength_ = true;
|
||||
}
|
||||
else if (ptr[0] == '\r' && ptr[1] == '\n') {
|
||||
size_t haveRead = end-ptr-2;
|
||||
if (haveRead > toRead_) {
|
||||
toRead_ = 0;
|
||||
}
|
||||
else {
|
||||
toRead_ -= haveRead;
|
||||
}
|
||||
if (toRead_ == 0) {
|
||||
complete_ = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
++ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (r < 0) {
|
||||
if (!SOCKET_WOULDBLOCK_ERROR( SOCKET_ERRNO )) {
|
||||
complete_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bool complete() {
|
||||
step();
|
||||
return complete_;
|
||||
}
|
||||
void rewind() {
|
||||
curRd_ = head_;
|
||||
curOffset_ = 0;
|
||||
}
|
||||
size_t read( void * ptr, size_t size) {
|
||||
step();
|
||||
if (!head_) {
|
||||
return 0;
|
||||
}
|
||||
if (!curRd_) {
|
||||
curRd_ = head_;
|
||||
assert( curOffset_ == 0 );
|
||||
}
|
||||
size_t copied = 0;
|
||||
while( size > 0) {
|
||||
assert( curRd_->size_ <= sizeof( curRd_->data_ ) );
|
||||
size_t toCopy = curRd_->size_ - curOffset_;
|
||||
if (toCopy > size) {
|
||||
toCopy = size;
|
||||
}
|
||||
memcpy( ptr, &curRd_->data_[curOffset_], toCopy );
|
||||
curOffset_ += toCopy;
|
||||
assert( curOffset_ <= sizeof(curRd_->data_) );
|
||||
ptr = ((char *)ptr)+toCopy;
|
||||
size -= toCopy;
|
||||
copied += toCopy;
|
||||
if (curOffset_ == curRd_->size_) {
|
||||
if (curRd_->next_ != 0) {
|
||||
curRd_ = curRd_->next_;
|
||||
curOffset_ = 0;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return copied;
|
||||
}
|
||||
|
||||
Chunk * head_;
|
||||
Chunk * curRd_;
|
||||
Chunk * curWr_;
|
||||
size_t curOffset_;
|
||||
size_t toRead_;
|
||||
bool complete_;
|
||||
bool gotLength_;
|
||||
SOCKET socket_;
|
||||
sockaddr_in addr_;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
I_HTTPRequest * NewHTTPRequest( char const * url )
|
||||
{
|
||||
static bool socketsInited;
|
||||
if (!socketsInited) {
|
||||
socketsInited = true;
|
||||
INIT_SOCKET_LIBRARY();
|
||||
}
|
||||
if (strncmp( url, "http://", 7 )) {
|
||||
return 0;
|
||||
}
|
||||
url += 7;
|
||||
char const * path = strchr( url, '/' );
|
||||
if (!path) {
|
||||
return 0;
|
||||
}
|
||||
char name[ 256 ];
|
||||
if (path-url > 255) {
|
||||
return 0;
|
||||
}
|
||||
strncpy( name, url, path-url );
|
||||
name[path-url] = 0;
|
||||
char * port = strrchr( name, ':' );
|
||||
unsigned short iport = 80;
|
||||
if (port) {
|
||||
*port = 0;
|
||||
iport = (unsigned short)( strtol( port+1, &port, 10 ) );
|
||||
}
|
||||
HTTPQuery * q = new HTTPQuery;
|
||||
q->setQuery( name, iport, path );
|
||||
return q;
|
||||
}
|
||||
|
||||
// TODO(ector):
|
||||
// Currently extremely bad implementation - busy waits!
|
||||
std::string HTTPDownloadText(const char *url)
|
||||
{
|
||||
I_HTTPRequest *r = NewHTTPRequest(url);
|
||||
int timeout = 10;
|
||||
std::string text = "";
|
||||
time_t t;
|
||||
t = 0;
|
||||
char buf[4096];
|
||||
while (true)
|
||||
{
|
||||
r->step();
|
||||
size_t rd = r->read(buf, 4096);
|
||||
if (rd > 0)
|
||||
{
|
||||
buf[rd] = 0;
|
||||
text += buf;
|
||||
}
|
||||
else {
|
||||
if (r->complete())
|
||||
goto next;
|
||||
|
||||
if (!t) {
|
||||
time(&t);
|
||||
}
|
||||
else {
|
||||
time_t t2;
|
||||
time(&t2);
|
||||
if (t2 > t + timeout) {
|
||||
fprintf( stderr, "timeout\n");
|
||||
goto next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
next:
|
||||
r->dispose();
|
||||
return text;
|
||||
}
|
||||
|
||||
void UnittestMyNetwork()
|
||||
{
|
||||
I_HTTPRequest * r = NewHTTPRequest( "http://www.cisco.com/" );
|
||||
char buf[1024];
|
||||
while( !r->complete()) {
|
||||
r->step();
|
||||
while( r->read( buf, sizeof( buf ) ) )
|
||||
;
|
||||
}
|
||||
char buf2[100000];
|
||||
r->rewind();
|
||||
while( r->read( buf2, sizeof( buf2 ) ) )
|
||||
;
|
||||
r->dispose();
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
// Under MIT licence from http://www.mindcontrol.org/~hplus/http-get.html
|
||||
|
||||
#if !defined( mynetwork_h )
|
||||
#define mynetwork_h
|
||||
|
||||
#include <string>
|
||||
|
||||
// I_HTTPRequest will run until it's received all available data
|
||||
// from the query. You can rewind and read the data received just
|
||||
// like a regular stream. Reading will return 0 bytes when at the
|
||||
// end, even if the query isn't yet complete. Test for completeness
|
||||
// with complete(). You need to step() the query every so often to
|
||||
// retrieve more data. Calling complete() and rewind() may step
|
||||
// the query.
|
||||
class I_HTTPRequest {
|
||||
public:
|
||||
virtual ~I_HTTPRequest() {}
|
||||
virtual void dispose() = 0;
|
||||
virtual void step() = 0;
|
||||
virtual bool complete() = 0;
|
||||
virtual void rewind() = 0;
|
||||
virtual size_t read(void * ptr, size_t data) = 0;
|
||||
};
|
||||
|
||||
// The format of "url" is "http://host:port/path". Name resolution
|
||||
// will be done synchronously, which can be a problem.
|
||||
// This request will NOT deal with user names and passwords. You
|
||||
// have been warned!
|
||||
I_HTTPRequest * NewHTTPRequest(char const * url);
|
||||
|
||||
std::string HTTPDownloadText(const char *url);
|
||||
|
||||
#endif
|
||||
|
@ -120,8 +120,8 @@ u32 HashFNV1(const u8* ptr, int length)
|
||||
}
|
||||
|
||||
|
||||
// Terribly stupid hash - but can't go back now :)
|
||||
// Don't use for new things. At least it's fast.
|
||||
// Stupid hash - but can't go back now :)
|
||||
// Don't use for new things. At least it's reasonably fast.
|
||||
u32 HashEctor(const u8* ptr, int length)
|
||||
{
|
||||
u32 crc = 0;
|
||||
@ -134,5 +134,3 @@ u32 HashEctor(const u8* ptr, int length)
|
||||
|
||||
return(crc);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user