20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <sys/select.h>
25 #include <arpa/inet.h>
27 #include <sys/ioctl.h>
29 #define WSAGetLastError() (errno)
43 #define NW_AGHBN_CANCEL 1
44 #define NW_AGHBN_LOOKUP 2
45 #define NW_AGHBN_READ 3
73 OutputDebugString(
"Aborting....\n");
80 OutputDebugString(
"Aborted....\n");
148 char *filestart = NULL;
149 char *dirstart = NULL;
150 for(
int i = strlen(pURL);
i>=0;
i--)
156 filestart = pURL+
i+1;
166 if((dirstart==NULL) || (filestart==NULL))
175 strncpy(
m_szHost,pURL,(dirstart-pURL));
182 if ( (thread_id = SDL_CreateThread(
HTTPObjThread,
this)) == NULL )
197 SDL_WaitThread(thread_id, NULL);
226 char szCommand[1000];
241 send(
m_DataSock,szCommand,strlen(szCommand),0);
247 pcode = strchr(p,
' ')+1;
281 if(
strnicmp(p,
"Content-Length:",strlen(
"Content-Length:"))==0)
283 char *
s = strchr(p,
' ')+1;
327 ip = inet_addr((
const char *)
m_szHost);
354 se = getservbyname(
"http", NULL);
359 hostaddr.sin_port = htons(80);
363 hostaddr.sin_port = se->s_port;
365 hostaddr.sin_family = AF_INET;
367 memcpy(&hostaddr.sin_addr, &ip, 4);
401 memcpy(&hostaddr.sin_addr,&ip,4);
405 memset(&hostaddr.sin_zero, 0,
sizeof(hostaddr.sin_zero));
423 if ( select(0, NULL, &wfds, NULL, &timeout) )
425 if ( select(
m_DataSock+1, NULL, &wfds, NULL, &timeout) )
471 bool gotdata =
false;
536 char sDataBuffer[4096];
543 timeout.tv_usec = 500;
555 select(0, &wfds, NULL, NULL, &timeout);
557 select(
m_DataSock+1, &wfds, NULL, NULL, &timeout);
565 nBytesRecv = recv(
m_DataSock, (
char *)&sDataBuffer,
sizeof(sDataBuffer), 0);
583 if (nBytesRecv > 0 ) {
584 fwrite(sDataBuffer, nBytesRecv, 1,
LOCALFILE);
589 }
while (nBytesRecv > 0);
631 http_lastaslu->
abort =
true;
635 memset(&newaslu->
ip,0,
sizeof(
unsigned int));
636 newaslu->
host = hostname;
637 newaslu->
done =
false;
638 newaslu->
error =
false;
639 newaslu->
abort =
false;
640 http_lastaslu = newaslu;
641 httpaslu.
done =
false;
646 HOSTENT *he = gethostbyname(hostname);
649 newaslu->
error =
true;
650 }
else if ( !newaslu->
abort ) {
651 memcpy( &newaslu->
ip, he->h_addr_list[0],
sizeof(
uint) );
652 newaslu->
done =
true;
668 http_lastaslu->
abort =
true;
669 http_lastaslu = NULL;
678 http_lastaslu = NULL;
679 memcpy(ip,&httpaslu.
ip,
sizeof(
unsigned int));
682 else if(httpaslu.
error)
685 http_lastaslu = NULL;
708 lookup->
error =
true;
715 else if(!lookup->
abort)
717 memcpy(&lookup->
ip,he->h_addr_list[0],
sizeof(
unsigned int));
#define HTTP_STATE_FILE_NOT_FOUND
#define HTTP_STATE_SOCKET_ERROR
async_dns_lookup httpaslu
#define HTTP_STATE_RECV_FAILED
#define HTTP_STATE_FILE_RECEIVED
#define strnicmp(s1, s2, n)
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
#define HTTP_STATE_CANT_WRITE_FILE
#define HTTP_STATE_UNKNOWN_ERROR
#define HTTP_STATE_CONNECTED
#define HTTP_STATE_RECEIVING
GLbitfield GLuint64 timeout
void GetFile(char *URL, char *localfile)
#define HTTP_STATE_URL_PARSING_ERROR
#define WSAGetLastError()
#define HTTP_STATE_STARTUP
int HTTPObjThread(void *obj)
#define HTTP_STATE_INTERNAL_ERROR
int http_gethostbynameworker(void *parm)
GLsizei GLsizei GLuint * obj
int http_Asyncgethostbyname(unsigned int *ip, int command, char *hostname)
struct _async_dns_lookup async_dns_lookup
ChttpGet(char *URL, char *localfile)
#define HTTP_STATE_CANT_CONNECT
#define _beginthread(x, y, z)
async_dns_lookup * http_lastaslu
#define HTTP_STATE_HOST_NOT_FOUND