2005-02-28 07:16:19 +00:00
# include "quakedef.h"
2004-08-23 01:40:25 +00:00
# ifdef WEBSERVER
# include "iweb.h"
2005-11-29 13:14:15 +00:00
# include "netinc.h"
2004-08-23 01:40:25 +00:00
2005-11-29 13:14:15 +00:00
//FIXME: Before any admins use this for any serious usage, make the server send bits of file slowly.
2004-08-23 01:40:25 +00:00
static qboolean httpserverinitied = false ;
2006-03-14 02:50:56 +00:00
qboolean httpserverfailed = false ;
2004-08-23 01:40:25 +00:00
static int httpserversocket ;
2013-08-06 02:19:06 +00:00
static int httpserverport ;
2016-07-12 00:40:13 +00:00
#if 0 //def WEBSVONLY
2013-08-06 02:19:06 +00:00
static int natpmpsocket = INVALID_SOCKET ;
static int natpmptime ;
2016-07-12 00:40:13 +00:00
# ifdef _WIN32
2013-08-06 02:19:06 +00:00
# include <mmsystem.h>
2016-07-12 00:40:13 +00:00
# endif
2013-08-06 02:19:06 +00:00
static void sendnatpmp ( int port )
{
struct sockaddr_in router ;
struct
{
qbyte ver ;
qbyte op ;
short reserved1 ;
short privport ; short pubport ;
int mapping_expectancy ;
} pmpreqmsg ;
int curtime = timeGetTime ( ) ;
if ( natpmpsocket = = INVALID_SOCKET )
{
unsigned long _true = true ;
2016-07-12 00:40:13 +00:00
natpmpsocket = socket ( AF_INET , SOCK_CLOEXEC | SOCK_DGRAM , 0 ) ;
2013-08-06 02:19:06 +00:00
if ( natpmpsocket = = INVALID_SOCKET )
return ;
ioctlsocket ( natpmpsocket , FIONBIO , & _true ) ;
}
else if ( curtime - natpmptime < 0 )
return ;
natpmptime = curtime + 60 * 1000 ;
memset ( & router , 0 , sizeof ( router ) ) ;
router . sin_family = AF_INET ;
router . sin_port = htons ( 5351 ) ;
router . sin_addr . S_un . S_un_b . s_b1 = 192 ;
router . sin_addr . S_un . S_un_b . s_b2 = 168 ;
router . sin_addr . S_un . S_un_b . s_b3 = 0 ;
router . sin_addr . S_un . S_un_b . s_b4 = 1 ;
pmpreqmsg . ver = 0 ;
pmpreqmsg . op = 0 ;
pmpreqmsg . reserved1 = htons ( 0 ) ;
pmpreqmsg . privport = htons ( port ) ;
pmpreqmsg . pubport = htons ( port ) ;
pmpreqmsg . mapping_expectancy = htons ( 60 * 5 ) ;
sendto ( natpmpsocket , ( void * ) & pmpreqmsg , 2 , 0 , ( struct sockaddr * ) & router , sizeof ( router ) ) ;
pmpreqmsg . op = 2 ;
sendto ( natpmpsocket , ( void * ) & pmpreqmsg , sizeof ( pmpreqmsg ) , 0 , ( struct sockaddr * ) & router , sizeof ( router ) ) ;
}
void checknatpmp ( int port )
{
struct
{
qbyte ver ; qbyte op ; short resultcode ;
int age ;
union
{
struct
{
short privport ; short pubport ;
int mapping_expectancy ;
} ;
qbyte ipv4 [ 4 ] ;
} ;
} pmpreqrep ;
struct sockaddr_in from ;
int fromlen = sizeof ( from ) ;
int len ;
static int oldip = - 1 ;
static short oldport ;
memset ( & pmpreqrep , 0 , sizeof ( pmpreqrep ) ) ;
sendnatpmp ( port ) ;
if ( natpmpsocket = = INVALID_SOCKET )
len = - 1 ;
else
len = recvfrom ( natpmpsocket , ( void * ) & pmpreqrep , sizeof ( pmpreqrep ) , 0 , ( struct sockaddr * ) & from , & fromlen ) ;
if ( len = = 12 & & pmpreqrep . op = = 128 )
{
if ( oldip ! = * ( int * ) pmpreqrep . ipv4 )
{
oldip = * ( int * ) pmpreqrep . ipv4 ;
oldport = 0 ;
IWebPrintf ( " Public ip is %i.%i.%i.%i \n " , pmpreqrep . ipv4 [ 0 ] , pmpreqrep . ipv4 [ 1 ] , pmpreqrep . ipv4 [ 2 ] , pmpreqrep . ipv4 [ 3 ] ) ;
}
}
else if ( len = = 16 & & pmpreqrep . op = = 129 )
{
if ( oldport ! = pmpreqrep . pubport )
{
oldport = pmpreqrep . pubport ;
IWebPrintf ( " Public udp port %i (local %i) \n " , ntohs ( pmpreqrep . pubport ) , ntohs ( pmpreqrep . privport ) ) ;
}
}
else if ( len = = 16 & & pmpreqrep . op = = 130 )
{
if ( oldport ! = pmpreqrep . pubport )
{
oldport = pmpreqrep . pubport ;
IWebPrintf ( " Public tcp port %i (local %i) \n " , ntohs ( pmpreqrep . pubport ) , ntohs ( pmpreqrep . privport ) ) ;
}
}
}
# else
void checknatpmp ( int port )
{
}
# endif
2004-08-23 01:40:25 +00:00
2004-09-20 23:25:38 +00:00
typedef enum { HTTP_WAITINGFORREQUEST , HTTP_SENDING } http_mode_t ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
# ifndef _WIN32
static qboolean HTTP_DoAccepts ( int epfd ) ;
struct http_epoll_ctx
{
struct epollctx_s pub ;
int epollfd ;
} ;
static void HTTP_ServerEPolled ( struct epollctx_s * pubctx , unsigned int ev )
{
struct http_epoll_ctx * ctx = ( struct http_epoll_ctx * ) pubctx ;
if ( ! HTTP_DoAccepts ( ctx - > epollfd ) )
{
int e = neterrno ( ) ;
switch ( e )
{
/*case NET_EWOULDBLOCK:
break ;
case NET_ECONNABORTED :
case NET_ECONNRESET :
Con_TPrintf ( " Connection lost or aborted \n " ) ;
break ; */
default :
IWebPrintf ( " NET_GetPacket: %s \n " , strerror ( e ) ) ;
break ;
}
}
}
# endif
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
qboolean HTTP_ServerInit ( int epfd , int port )
2011-05-19 13:34:07 +00:00
{
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
struct sockaddr_qstorage address ;
2004-08-23 01:40:25 +00:00
unsigned long _true = true ;
int i ;
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
memset ( & address , 0 , sizeof ( address ) ) ;
//check for interface binding option. this also forces ipv4, oh well.
if ( ( i = COM_CheckParm ( " -ip " ) ) ! = 0 & & i < com_argc )
{
( ( struct sockaddr_in * ) & address ) - > sin_addr . s_addr = inet_addr ( com_argv [ i + 1 ] ) ;
Con_TPrintf ( " Binding to IP Interface Address of %s \n " ,
inet_ntoa ( ( ( struct sockaddr_in * ) & address ) - > sin_addr ) ) ;
( ( struct sockaddr_in * ) & address ) - > sin_family = AF_INET ;
if ( port ! = PORT_ANY )
( ( struct sockaddr_in * ) & address ) - > sin_port = htons ( ( short ) port ) ;
}
else
{ //otherwise just use ipv6
( ( struct sockaddr_in6 * ) & address ) - > sin6_family = AF_INET6 ;
if ( port ! = PORT_ANY )
( ( struct sockaddr_in6 * ) & address ) - > sin6_port = htons ( ( short ) port ) ;
}
if ( ( httpserversocket = socket ( ( ( struct sockaddr * ) & address ) - > sa_family , SOCK_STREAM , IPPROTO_TCP ) ) = = - 1 )
2004-08-23 01:40:25 +00:00
{
2014-02-07 08:38:40 +00:00
IWebPrintf ( " HTTP_ServerInit: socket: %s \n " , strerror ( neterrno ( ) ) ) ;
2006-03-14 02:50:56 +00:00
httpserverfailed = true ;
return false ;
2004-08-23 01:40:25 +00:00
}
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
if ( ( ( struct sockaddr_in6 * ) & address ) - > sin6_family = = AF_INET6 & & ! memcmp ( ( ( struct sockaddr_in6 * ) & address ) - > sin6_addr . s6_addr , " \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 " , 16 ) )
{ //in6addr_any, allow ipv4 too, if we can do hybrid sockets.
unsigned long v6only = false ;
setsockopt ( httpserversocket , IPPROTO_IPV6 , IPV6_V6ONLY , ( char * ) & v6only , sizeof ( v6only ) ) ;
}
2004-08-23 01:40:25 +00:00
if ( ioctlsocket ( httpserversocket , FIONBIO , & _true ) = = - 1 )
{
2014-02-07 08:38:40 +00:00
IWebPrintf ( " HTTP_ServerInit: ioctl FIONBIO: %s \n " , strerror ( neterrno ( ) ) ) ;
2006-03-14 02:50:56 +00:00
httpserverfailed = true ;
return false ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
if ( bind ( httpserversocket , ( void * ) & address , sizeof ( address ) ) = = - 1 )
2004-08-23 01:40:25 +00:00
{
closesocket ( httpserversocket ) ;
2009-11-04 21:16:50 +00:00
IWebPrintf ( " HTTP_ServerInit: failed to bind to socket \n " ) ;
2006-03-14 02:50:56 +00:00
httpserverfailed = true ;
return false ;
2004-08-23 01:40:25 +00:00
}
2011-05-19 13:34:07 +00:00
2004-08-23 01:40:25 +00:00
listen ( httpserversocket , 3 ) ;
httpserverinitied = true ;
2006-03-14 09:20:07 +00:00
httpserverfailed = false ;
2013-08-06 02:19:06 +00:00
httpserverport = port ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
# ifndef _WIN32
if ( epfd > = 0 )
{
static struct http_epoll_ctx ctx ;
struct epoll_event ev ;
ctx . epollfd = epfd ;
ctx . pub . Polled = HTTP_ServerEPolled ;
ev . events = EPOLLIN ;
ev . data . ptr = & ctx ;
epoll_ctl ( epfd , EPOLL_CTL_ADD , httpserversocket , & ev ) ;
}
# endif
2004-08-23 01:40:25 +00:00
IWebPrintf ( " HTTP server is running \n " ) ;
2006-03-14 02:50:56 +00:00
return true ;
2004-08-23 01:40:25 +00:00
}
void HTTP_ServerShutdown ( void )
{
closesocket ( httpserversocket ) ;
IWebPrintf ( " HTTP server closed \n " ) ;
httpserverinitied = false ;
}
typedef struct HTTP_active_connections_s {
2021-06-01 09:23:49 +00:00
# ifndef _WIN32
struct epollctx_s pub ;
int epfd ;
# endif
2013-03-12 22:47:42 +00:00
SOCKET datasock ;
2014-09-08 23:47:19 +00:00
char peername [ 256 ] ;
2005-12-21 03:07:33 +00:00
vfsfile_t * file ;
2004-08-23 01:40:25 +00:00
struct HTTP_active_connections_s * next ;
http_mode_t mode ;
qboolean modeswitched ;
qboolean closeaftertransaction ;
2013-06-23 02:17:02 +00:00
qboolean acceptgzip ;
2004-08-23 01:40:25 +00:00
char * inbuffer ;
2013-03-12 22:47:42 +00:00
unsigned int inbuffersize ;
unsigned int inbufferused ;
2004-08-23 01:40:25 +00:00
char * outbuffer ;
2013-03-12 22:47:42 +00:00
unsigned int outbuffersize ;
unsigned int outbufferused ;
2004-08-23 01:40:25 +00:00
} HTTP_active_connections_t ;
static HTTP_active_connections_t * HTTP_ServerConnections ;
static int httpconnectioncount ;
2013-03-12 22:47:42 +00:00
static void ExpandInBuffer ( HTTP_active_connections_t * cl , unsigned int quant , qboolean fixedsize )
2004-08-23 01:40:25 +00:00
{
2013-03-12 22:47:42 +00:00
unsigned int newsize ;
2004-08-23 01:40:25 +00:00
if ( fixedsize )
newsize = quant ;
else
newsize = cl - > inbuffersize + quant ;
if ( newsize < = cl - > inbuffersize )
return ;
cl - > inbuffer = IWebRealloc ( cl - > inbuffer , newsize ) ;
cl - > inbuffersize = newsize ;
}
2013-03-12 22:47:42 +00:00
static void ExpandOutBuffer ( HTTP_active_connections_t * cl , unsigned int quant , qboolean fixedsize )
2004-08-23 01:40:25 +00:00
{
2013-03-12 22:47:42 +00:00
unsigned int newsize ;
2004-08-23 01:40:25 +00:00
if ( fixedsize )
newsize = quant ;
else
newsize = cl - > outbuffersize + quant ;
if ( newsize < = cl - > outbuffersize )
return ;
cl - > outbuffer = IWebRealloc ( cl - > outbuffer , newsize ) ;
cl - > outbuffersize = newsize ;
}
2021-06-01 09:23:49 +00:00
const char * HTTP_RunClient ( HTTP_active_connections_t * cl )
2004-08-23 01:40:25 +00:00
{
char * content ;
char * msg , * nl ;
2013-06-23 02:17:02 +00:00
char buf2 [ 2560 ] ; //short lived temp buffer.
char resource [ 2560 ] ;
2014-09-08 23:47:19 +00:00
char host [ 256 ] ;
2013-06-23 02:17:02 +00:00
char mode [ 80 ] ;
2004-08-23 01:40:25 +00:00
qboolean hostspecified ;
2013-03-12 22:47:42 +00:00
unsigned int contentlen ;
2004-08-23 01:40:25 +00:00
int HTTPmarkup ; //version
2006-04-05 04:31:05 +00:00
int localerrno ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
int ammount , wanted ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
switch ( cl - > mode )
2004-08-23 01:40:25 +00:00
{
2021-06-01 09:23:49 +00:00
case HTTP_WAITINGFORREQUEST :
if ( cl - > outbufferused )
Sys_Error ( " Persistant connection was waiting for input with unsent output " ) ;
ammount = cl - > inbuffersize - 1 - cl - > inbufferused ;
if ( ammount < 128 )
2004-08-23 01:40:25 +00:00
{
2021-06-01 09:23:49 +00:00
if ( cl - > inbuffersize > 128 * 1024 )
return " headers larger than 128kb " ; //that's just taking the piss.
2009-05-24 10:11:17 +00:00
2021-06-01 09:23:49 +00:00
ExpandInBuffer ( cl , 1500 , false ) ;
ammount = cl - > inbuffersize - 1 - cl - > inbufferused ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
if ( cl - > modeswitched )
2004-08-23 01:40:25 +00:00
{
2021-06-01 09:23:49 +00:00
ammount = 0 ;
}
else
{
//we can't try and recv 0 bytes as we use an expanding buffer
ammount = recv ( cl - > datasock , cl - > inbuffer + cl - > inbufferused , ammount , 0 ) ;
if ( ammount < 0 )
2004-08-23 01:40:25 +00:00
{
2021-06-01 09:23:49 +00:00
int e = neterrno ( ) ;
if ( e = = NET_EWOULDBLOCK ) //they closed on us. Assume end.
return NULL ;
return " recv error " ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
if ( ammount = = 0 )
return " peer closed connection " ;
}
cl - > modeswitched = false ;
cl - > inbufferused + = ammount ;
cl - > inbuffer [ cl - > inbufferused ] = ' \0 ' ;
content = NULL ;
msg = cl - > inbuffer ;
nl = strchr ( msg , ' \n ' ) ;
if ( ! nl )
return NULL ; //we need more... MORE!!! MORE I TELL YOU!!!!
//FIXME: COM_ParseOut recognises // comments, which is not correct.
msg = COM_ParseOut ( msg , mode , sizeof ( mode ) ) ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
msg = COM_ParseOut ( msg , resource , sizeof ( resource ) ) ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
if ( ! * resource )
return " not http " ; //even if they forgot to specify a resource, we didn't find an HTTP so we have no option but to close.
host [ 0 ] = ' ? ' ;
host [ 1 ] = 0 ;
hostspecified = false ;
if ( ! strnicmp ( resource , " http:// " , 7 ) )
{ //groan... 1.1 compliance requires parsing this correctly, without the client ever specifiying it.
char * slash ; //we don't do multiple hosts.
hostspecified = true ;
slash = strchr ( resource + 7 , ' / ' ) ;
if ( ! slash )
strcpy ( resource , " / " ) ;
else
2004-08-23 01:40:25 +00:00
{
2021-06-01 09:23:49 +00:00
int hlen = slash - ( resource + 7 ) ;
if ( hlen > sizeof ( host ) - 1 )
hlen = sizeof ( host ) - 1 ;
memcpy ( host , resource + 7 , hlen ) ;
host [ hlen ] = 0 ;
memmove ( resource , slash , strlen ( slash + 1 ) ) ; //just get rid of the http:// stuff.
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
}
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
if ( ! strcmp ( resource , " / " ) )
strcpy ( resource , " /index.html " ) ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
cl - > acceptgzip = false ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
msg = COM_ParseOut ( msg , buf2 , sizeof ( buf2 ) ) ;
contentlen = 0 ;
if ( ! strnicmp ( buf2 , " HTTP/ " , 5 ) )
{
if ( ! strncmp ( buf2 , " HTTP/1.1 " , 8 ) )
2004-08-23 01:40:25 +00:00
{
2021-06-01 09:23:49 +00:00
HTTPmarkup = 3 ;
cl - > closeaftertransaction = false ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
else if ( ! strncmp ( buf2 , " HTTP/1 " , 6 ) )
{
HTTPmarkup = 2 ;
cl - > closeaftertransaction = true ;
}
else
{
HTTPmarkup = 1 ; //0.9... lamer.
cl - > closeaftertransaction = true ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
//expect X lines containing options.
//then a blank line. Don't continue till we have that.
2013-06-23 02:17:02 +00:00
2021-06-01 09:23:49 +00:00
msg = nl + 1 ;
while ( 1 )
2004-08-23 01:40:25 +00:00
{
2021-06-01 09:23:49 +00:00
if ( * msg = = ' \r ' )
msg + + ;
if ( * msg = = ' \n ' )
2004-08-23 01:40:25 +00:00
{
2021-06-01 09:23:49 +00:00
msg + + ;
break ; //that was our blank line.
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
while ( * msg = = ' ' )
msg + + ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
if ( ! strnicmp ( msg , " Host: " , 6 ) ) //parse needed header fields
2004-08-23 01:40:25 +00:00
{
2021-06-01 09:23:49 +00:00
int l = 0 ;
msg + = 6 ;
while ( * msg = = ' ' | | * msg = = ' \t ' )
2004-08-23 01:40:25 +00:00
msg + + ;
2021-06-01 09:23:49 +00:00
while ( * msg ! = ' \r ' & & * msg ! = ' \n ' & & l < sizeof ( host ) - 1 )
host [ l + + ] = * msg + + ;
host [ l ] = 0 ;
hostspecified = true ;
}
else if ( ! strnicmp ( msg , " Content-Length: " , 16 ) ) //parse needed header fields
contentlen = strtoul ( msg + 16 , NULL , 0 ) ;
else if ( ! strnicmp ( msg , " Accept-Encoding: " , 16 ) ) //parse needed header fields
{
char * e ;
msg + = 16 ;
while ( * msg )
2014-09-08 23:47:19 +00:00
{
2021-06-01 09:23:49 +00:00
if ( * msg = = ' \n ' )
break ;
2014-09-08 23:47:19 +00:00
while ( * msg = = ' ' | | * msg = = ' \t ' )
msg + + ;
2021-06-01 09:23:49 +00:00
if ( * msg = = ' , ' )
2013-06-23 02:17:02 +00:00
{
2021-06-01 09:23:49 +00:00
msg + + ;
continue ;
}
e = msg ;
while ( * e )
{
if ( * e = = ' , ' | | * e = = ' \r ' | | * e = = ' \n ' )
2013-06-23 02:17:02 +00:00
break ;
2021-06-01 09:23:49 +00:00
e + + ;
2013-06-23 02:17:02 +00:00
}
2021-06-01 09:23:49 +00:00
while ( e > msg & & ( e [ - 1 ] = = ' ' | | e [ - 1 ] = = ' \t ' ) )
e - - ;
if ( e - msg = = 4 & & ! strncmp ( msg , " gzip " , 4 ) )
cl - > acceptgzip = true ;
while ( * msg & & * msg ! = ' \n ' & & * msg ! = ' , ' )
msg + + ;
2013-06-23 02:17:02 +00:00
}
2021-06-01 09:23:49 +00:00
}
else if ( ! strnicmp ( msg , " Transfer-Encoding: " , 18 ) ) //parse needed header fields
{
cl - > closeaftertransaction = true ;
goto notimplemented ;
}
else if ( ! strnicmp ( msg , " Connection: close " , 17 ) )
cl - > closeaftertransaction = true ;
else if ( ! strnicmp ( msg , " Connection: Keep-Alive " , 22 ) )
cl - > closeaftertransaction = false ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
while ( * msg ! = ' \n ' )
{
if ( ! * msg )
2004-08-23 01:40:25 +00:00
{
2021-06-01 09:23:49 +00:00
if ( msg = = cl - > inbuffer + cl - > inbufferused )
return NULL ;
else
return " Unexpected null byte " ;
2004-08-23 01:40:25 +00:00
}
msg + + ;
}
2021-06-01 09:23:49 +00:00
msg + + ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
}
else
{
HTTPmarkup = 0 ; //strimmed... totally...
cl - > closeaftertransaction = true ;
//don't bother running to nl.
}
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
if ( cl - > inbufferused - ( msg - cl - > inbuffer ) < contentlen )
return NULL ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
cl - > modeswitched = true ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
if ( contentlen )
{
content = IWebMalloc ( contentlen + 1 ) ;
memcpy ( content , msg , contentlen + 1 ) ;
}
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
memmove ( cl - > inbuffer , cl - > inbuffer + ( msg - cl - > inbuffer + contentlen ) , cl - > inbufferused - ( msg - cl - > inbuffer + contentlen ) ) ;
cl - > inbufferused - = msg - cl - > inbuffer + contentlen ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
if ( HTTPmarkup = = 3 & & ! hostspecified ) //1.1 requires the host to be specified... we ca,just ignore it as we're not routing or imitating two servers. (for complience we need to encourage the client to send - does nothing for compatability or anything, just compliance to spec. not always the same thing)
{
msg = " HTTP/1.1 400 Bad Request \r \n " /*"Content-Type: application/octet-stream\r\n"*/ " Content-Length: 69 \r \n " " Server: " FULLENGINENAME " /0 \r \n " " \r \n " " 400 Bad Request \r \n Your client failed to provide the host header line " ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
IWebPrintf ( " %s: no host specified \n " , cl - > peername ) ;
2014-09-14 01:45:11 +00:00
2021-06-01 09:23:49 +00:00
ammount = strlen ( msg ) ;
ExpandOutBuffer ( cl , ammount , true ) ;
memcpy ( cl - > outbuffer , msg , ammount ) ;
cl - > outbufferused = ammount ;
cl - > mode = HTTP_SENDING ;
}
else if ( ! stricmp ( mode , " GET " ) | | ! stricmp ( mode , " HEAD " ) | | ! stricmp ( mode , " POST " ) )
{
qboolean gzipped = false ;
if ( * resource ! = ' / ' )
{
resource [ 0 ] = ' / ' ;
resource [ 1 ] = 0 ; //I'm lazy, they need to comply
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
IWebPrintf ( " %s: Download request for \" http://%s/%s \" \n " , cl - > peername , host , resource + 1 ) ;
if ( ! strnicmp ( mode , " P " , 1 ) ) //when stuff is posted, data is provided. Give an error message if we couldn't do anything with that data.
cl - > file = IWebGenerateFile ( resource + 1 , content , contentlen ) ;
else
2007-09-17 20:35:39 +00:00
{
2021-06-01 09:23:49 +00:00
char filename [ MAX_OSPATH ] , * q ;
cl - > file = NULL ;
Q_strncpyz ( filename , resource + 1 , sizeof ( filename ) ) ;
q = strchr ( filename , ' ? ' ) ;
if ( q ) * q = 0 ;
2013-06-23 02:17:02 +00:00
2021-06-01 09:23:49 +00:00
if ( SV_AllowDownload ( filename ) )
2009-05-24 10:11:17 +00:00
{
2021-06-01 09:23:49 +00:00
char nbuf [ MAX_OSPATH ] ;
2011-05-19 13:34:07 +00:00
2021-06-01 09:23:49 +00:00
if ( cl - > acceptgzip & & strlen ( filename ) < sizeof ( nbuf ) - 4 )
2009-05-24 10:11:17 +00:00
{
2021-06-01 09:23:49 +00:00
Q_strncpyz ( nbuf , filename , sizeof ( nbuf ) ) ;
Q_strncatz ( nbuf , " .gz " , sizeof ( nbuf ) ) ;
cl - > file = FS_OpenVFS ( nbuf , " rb " , FS_GAME ) ;
2009-05-24 10:11:17 +00:00
}
2021-06-01 09:23:49 +00:00
if ( cl - > file )
gzipped = true ;
else
cl - > file = FS_OpenVFS ( filename , " rb " , FS_GAME ) ;
2009-05-24 10:11:17 +00:00
}
2021-06-01 09:23:49 +00:00
2004-08-23 01:40:25 +00:00
if ( ! cl - > file )
{
2021-06-01 09:23:49 +00:00
cl - > file = IWebGenerateFile ( resource + 1 , content , contentlen ) ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
}
if ( ! cl - > file )
{
IWebPrintf ( " %s: 404 - not found \n " , cl - > peername ) ;
if ( HTTPmarkup > = 3 )
msg = " HTTP/1.1 404 Not Found \r \n " " Content-Type: text/plain \r \n " " Content-Length: 15 \r \n " " Server: " FULLENGINENAME " /0 \r \n " " \r \n " " 404 Bad address " ;
else if ( HTTPmarkup = = 2 )
msg = " HTTP/1.0 404 Not Found \r \n " " Content-Type: text/plain \r \n " " Content-Length: 15 \r \n " " Server: " FULLENGINENAME " /0 \r \n " " \r \n " " 404 Bad address " ;
else if ( HTTPmarkup )
msg = " HTTP/0.9 404 Not Found \r \n " " \r \n " " 404 Bad address " ;
2004-08-23 01:40:25 +00:00
else
2021-06-01 09:23:49 +00:00
msg = " <HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD><BODY>404 Not Found<BR>The specified file could not be found on the server</HEAD></HTML> " ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
ammount = strlen ( msg ) ;
ExpandOutBuffer ( cl , ammount , true ) ;
memcpy ( cl - > outbuffer , msg , ammount ) ;
cl - > outbufferused = ammount ;
cl - > mode = HTTP_SENDING ;
}
else
{
2021-09-01 03:54:40 +00:00
const char * mimeline ;
if ( strstr ( resource , " .htm " ) )
mimeline = " Content-Type: text/html \r \n " ;
else if ( strstr ( resource , " .wasm " ) )
mimeline = " Content-Type: application/wasm \r \n " ;
else if ( strstr ( resource , " .js " ) )
mimeline = " Content-Type: text/javascript \r \n " ;
else
2021-10-05 05:06:10 +00:00
mimeline = " " ;
2021-09-01 03:54:40 +00:00
2021-06-01 09:23:49 +00:00
//fixme: add connection: keep-alive or whatever so that ie3 is happy...
if ( HTTPmarkup > = 3 )
2021-09-01 03:54:40 +00:00
sprintf ( resource , " HTTP/1.1 200 OK \r \n " " %s%s " " Connection: %s \r \n " " Content-Length: %i \r \n " " Server: " FULLENGINENAME " /0 \r \n " " \r \n " , mimeline , gzipped ? " Content-Encoding: gzip \r \n Cache-Control: public, max-age=86400 \r \n " : " " , cl - > closeaftertransaction ? " close " : " keep-alive " , ( int ) VFS_GETLEN ( cl - > file ) ) ;
2021-06-01 09:23:49 +00:00
else if ( HTTPmarkup = = 2 )
2021-09-01 03:54:40 +00:00
sprintf ( resource , " HTTP/1.0 200 OK \r \n " " %s%s " " Connection: %s \r \n " " Content-Length: %i \r \n " " Server: " FULLENGINENAME " /0 \r \n " " \r \n " , mimeline , gzipped ? " Content-Encoding: gzip \r \n Cache-Control: public, max-age=86400 \r \n " : " " , cl - > closeaftertransaction ? " close " : " keep-alive " , ( int ) VFS_GETLEN ( cl - > file ) ) ;
2021-06-01 09:23:49 +00:00
else if ( HTTPmarkup )
sprintf ( resource , " HTTP/0.9 200 OK \r \n \r \n " ) ;
else
strcpy ( resource , " " ) ;
msg = resource ;
2011-05-19 13:34:07 +00:00
2021-06-01 09:23:49 +00:00
if ( * mode = = ' H ' | | * mode = = ' h ' )
{
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
VFS_CLOSE ( cl - > file ) ;
cl - > file = NULL ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
ammount = strlen ( msg ) ;
ExpandOutBuffer ( cl , ammount , true ) ;
memcpy ( cl - > outbuffer , msg , ammount ) ;
cl - > outbufferused = ammount ;
cl - > mode = HTTP_SENDING ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
}
//PUT/POST must support chunked transfer encoding for 1.1 compliance.
2004-08-23 01:40:25 +00:00
/* else if (!stricmp(mode, "PUT")) //put is replacement of a resource. (file uploads)
2021-06-01 09:23:49 +00:00
{
}
2004-08-23 01:40:25 +00:00
*/
2021-06-01 09:23:49 +00:00
else
{
notimplemented :
if ( HTTPmarkup > = 3 )
msg = " HTTP/1.1 501 Not Implemented \r \n \r \n " ;
else if ( HTTPmarkup = = 2 )
msg = " HTTP/1.0 501 Not Implemented \r \n \r \n " ;
else if ( HTTPmarkup )
msg = " HTTP/0.9 501 Not Implemented \r \n \r \n " ;
2004-08-23 01:40:25 +00:00
else
{
2021-06-01 09:23:49 +00:00
msg = NULL ;
return " unsupported http version " ;
}
IWebPrintf ( " %s: 501 - not implemented \n " , cl - > peername ) ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
if ( msg )
{
ammount = strlen ( msg ) ;
ExpandOutBuffer ( cl , ammount , true ) ;
memcpy ( cl - > outbuffer , msg , ammount ) ;
cl - > outbufferused = ammount ;
cl - > mode = HTTP_SENDING ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
}
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
if ( content )
IWebFree ( content ) ;
break ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
case HTTP_SENDING :
if ( cl - > outbufferused < 8192 )
{
if ( cl - > file )
2004-08-23 01:40:25 +00:00
{
2021-06-01 09:23:49 +00:00
ExpandOutBuffer ( cl , 32768 , true ) ;
wanted = cl - > outbuffersize - cl - > outbufferused ;
ammount = VFS_READ ( cl - > file , cl - > outbuffer + cl - > outbufferused , wanted ) ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
if ( ! ammount )
{
VFS_CLOSE ( cl - > file ) ;
cl - > file = NULL ;
2012-01-28 10:30:44 +00:00
2021-06-01 09:23:49 +00:00
IWebPrintf ( " %s: Download complete \n " , cl - > peername ) ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
else
cl - > outbufferused + = ammount ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
}
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
ammount = send ( cl - > datasock , cl - > outbuffer , cl - > outbufferused , 0 ) ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
if ( ammount = = - 1 )
{
localerrno = neterrno ( ) ;
if ( localerrno ! = NET_EWOULDBLOCK )
return " some error when sending " ;
}
else if ( ammount | | ! cl - > outbufferused )
{
memcpy ( cl - > outbuffer , cl - > outbuffer + ammount , cl - > outbufferused - ammount ) ;
cl - > outbufferused - = ammount ;
if ( ! cl - > outbufferused & & ! cl - > file )
2004-08-23 01:40:25 +00:00
{
2021-06-01 09:23:49 +00:00
cl - > modeswitched = true ;
cl - > mode = HTTP_WAITINGFORREQUEST ;
if ( cl - > closeaftertransaction )
return " file sent " ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
}
else
return " peer prematurely closed connection " ;
break ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
/* case HTTP_RECEIVING:
sent = recv ( cl - > datasock , resource , ammount , 0 ) ;
if ( sent = = - 1 )
{
if ( qerrno ! = EWOULDBLOCK ) //they closed on us. Assume end.
2004-08-23 01:40:25 +00:00
{
2021-06-01 09:23:49 +00:00
VFS_CLOSE ( cl - > file ) ;
cl - > file = NULL ;
cl - > close = true ;
continue ;
2004-08-23 01:40:25 +00:00
}
}
2021-06-01 09:23:49 +00:00
if ( sent ! = 0 )
IWebFWrite ( resource , 1 , sent , cl - > file ) ;
break ; */
default :
return " Unknown state " ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
return NULL ;
2004-08-23 01:40:25 +00:00
}
2021-06-01 09:23:49 +00:00
void HTTP_RunExisting ( void )
{
const char * err ;
HTTP_active_connections_t * * link , * cl ;
link = & HTTP_ServerConnections ;
for ( link = & HTTP_ServerConnections ; * link ; )
{
cl = * link ;
err = HTTP_RunClient ( cl ) ;
if ( err )
{
IWebPrintf ( " %s: Closing connection: %s \n " , cl - > peername , err ) ;
* link = cl - > next ;
closesocket ( cl - > datasock ) ;
cl - > datasock = INVALID_SOCKET ;
if ( cl - > inbuffer )
IWebFree ( cl - > inbuffer ) ;
if ( cl - > outbuffer )
IWebFree ( cl - > outbuffer ) ;
if ( cl - > file )
VFS_CLOSE ( cl - > file ) ;
IWebFree ( cl ) ;
httpconnectioncount - - ;
continue ;
}
link = & ( * link ) - > next ;
}
}
# ifndef _WIN32
static void HTTP_ClientEPolled ( struct epollctx_s * pubctx , unsigned int ev )
{
HTTP_active_connections_t * cl = ( HTTP_active_connections_t * ) pubctx ;
const char * err = HTTP_RunClient ( cl ) ;
if ( err )
{
IWebPrintf ( " %s: Closing connection: %s \n " , cl - > peername , err ) ;
//should be automatic thanks to the closesocket, but do it just in case.
epoll_ctl ( cl - > epfd , EPOLL_CTL_DEL , cl - > datasock , NULL ) ;
closesocket ( cl - > datasock ) ;
cl - > datasock = INVALID_SOCKET ;
if ( cl - > inbuffer )
IWebFree ( cl - > inbuffer ) ;
if ( cl - > outbuffer )
IWebFree ( cl - > outbuffer ) ;
if ( cl - > file )
VFS_CLOSE ( cl - > file ) ;
IWebFree ( cl ) ;
httpconnectioncount - - ;
}
else
{
struct epoll_event ev ;
switch ( cl - > mode )
{
case HTTP_WAITINGFORREQUEST :
ev . events = EPOLLIN ;
break ;
case HTTP_SENDING :
ev . events = EPOLLOUT ;
break ;
default : //don't know, spam it.
ev . events = EPOLLIN | EPOLLOUT ;
break ;
}
ev . data . ptr = & cl - > pub ;
epoll_ctl ( cl - > epfd , EPOLL_CTL_ADD , cl - > datasock , & ev ) ;
}
}
# endif
static qboolean HTTP_DoAccepts ( int epfd )
2004-08-23 01:40:25 +00:00
{
2009-05-24 10:11:17 +00:00
struct sockaddr_qstorage from ;
2021-06-01 09:23:49 +00:00
int fromlen = sizeof ( from ) ;
HTTP_active_connections_t * cl ;
2007-09-04 20:54:24 +00:00
int _true = true ;
2021-06-01 09:23:49 +00:00
int clientsock = accept ( httpserversocket , ( struct sockaddr * ) & from , & fromlen ) ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
if ( clientsock < 0 )
return false ;
2004-08-23 01:40:25 +00:00
2021-06-01 09:23:49 +00:00
if ( ioctlsocket ( clientsock , FIONBIO , ( u_long * ) & _true ) = = - 1 )
{
IWebPrintf ( " HTTP_ServerInit: ioctl FIONBIO: %s \n " , strerror ( neterrno ( ) ) ) ;
closesocket ( clientsock ) ;
return false ;
}
cl = IWebMalloc ( sizeof ( HTTP_active_connections_t ) ) ;
NET_SockadrToString ( cl - > peername , sizeof ( cl - > peername ) , & from , sizeof ( from ) ) ;
IWebPrintf ( " %s: New http connection \n " , cl - > peername ) ;
cl - > datasock = clientsock ;
# ifndef _WIN32
if ( epfd > = 0 )
{
struct epoll_event ev ;
cl - > pub . Polled = HTTP_ClientEPolled ;
cl - > epfd = epfd ;
ev . events = EPOLLIN | EPOLLOUT ;
ev . data . ptr = & cl - > pub ;
epoll_ctl ( epfd , EPOLL_CTL_ADD , clientsock , & ev ) ;
}
else
# endif
{
cl - > next = HTTP_ServerConnections ;
HTTP_ServerConnections = cl ;
}
httpconnectioncount + + ;
return true ;
}
qboolean HTTP_ServerPoll ( qboolean httpserverwanted , int portnum ) //loop while true
{
2013-08-06 02:19:06 +00:00
if ( httpserverport ! = portnum & & httpserverinitied )
HTTP_ServerShutdown ( ) ;
2004-08-23 01:40:25 +00:00
if ( ! httpserverinitied )
{
if ( httpserverwanted )
2021-06-01 09:23:49 +00:00
return HTTP_ServerInit ( - 1 , portnum ) ;
2004-08-23 01:40:25 +00:00
return false ;
}
else if ( ! httpserverwanted )
{
HTTP_ServerShutdown ( ) ;
return false ;
}
2013-08-06 02:19:06 +00:00
checknatpmp ( httpserverport ) ;
2004-08-23 01:40:25 +00:00
if ( httpconnectioncount > 32 )
return false ;
2021-06-01 09:23:49 +00:00
if ( ! HTTP_DoAccepts ( - 1 ) )
2004-08-23 01:40:25 +00:00
{
2014-02-07 08:38:40 +00:00
int e = neterrno ( ) ;
if ( e = = NET_EWOULDBLOCK )
2004-08-23 01:40:25 +00:00
{
HTTP_RunExisting ( ) ;
return false ;
}
2014-02-07 08:38:40 +00:00
if ( e = = NET_ECONNABORTED | | e = = NET_ECONNRESET )
2004-08-23 01:40:25 +00:00
{
2013-11-29 14:36:47 +00:00
Con_TPrintf ( " Connection lost or aborted \n " ) ;
2004-08-23 01:40:25 +00:00
return false ;
}
2014-09-08 23:47:19 +00:00
IWebPrintf ( " NET_GetPacket: %s \n " , strerror ( e ) ) ;
2004-08-23 01:40:25 +00:00
return false ;
}
return true ;
}
# endif