|
|
@ -15,9 +15,6 @@
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "stdpch.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <nel/misc/file.h>
|
|
|
|
#include <nel/misc/file.h>
|
|
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
extern "C"
|
|
|
@ -40,81 +37,80 @@ extern "C"
|
|
|
|
using namespace std;
|
|
|
|
using namespace std;
|
|
|
|
using namespace NLMISC;
|
|
|
|
using namespace NLMISC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/* Final states have negative value */
|
|
|
|
/* Final states have negative value */
|
|
|
|
typedef enum _FileState {
|
|
|
|
typedef enum _FileState {
|
|
|
|
FS_RETRY = -4,
|
|
|
|
FS_RETRY = -4,
|
|
|
|
FS_ERROR = -3,
|
|
|
|
FS_ERROR = -3,
|
|
|
|
FS_NO_DATA = -2,
|
|
|
|
FS_NO_DATA = -2,
|
|
|
|
FS_GOT_DATA = -1,
|
|
|
|
FS_GOT_DATA = -1,
|
|
|
|
FS_BEGIN = 0,
|
|
|
|
FS_BEGIN = 0,
|
|
|
|
FS_PENDING,
|
|
|
|
FS_PENDING,
|
|
|
|
FS_DO_CN,
|
|
|
|
FS_DO_CN,
|
|
|
|
FS_NEED_OPEN_FILE,
|
|
|
|
FS_NEED_OPEN_FILE,
|
|
|
|
FS_NEED_BODY,
|
|
|
|
FS_NEED_BODY,
|
|
|
|
FS_PARSE_DIR,
|
|
|
|
FS_PARSE_DIR,
|
|
|
|
FS_TRY_FTP
|
|
|
|
FS_TRY_FTP
|
|
|
|
} FileState;
|
|
|
|
} FileState;
|
|
|
|
|
|
|
|
|
|
|
|
/* This is the context structure for the this module */
|
|
|
|
/* This is the context structure for the this module */
|
|
|
|
typedef struct _file_info {
|
|
|
|
typedef struct _file_info {
|
|
|
|
FileState state; /* Current state of the connection */
|
|
|
|
FileState state; /* Current state of the connection */
|
|
|
|
char * local; /* Local representation of file name */
|
|
|
|
char * local; /* Local representation of file name */
|
|
|
|
struct stat stat_info; /* Contains actual file chosen */
|
|
|
|
struct stat stat_info; /* Contains actual file chosen */
|
|
|
|
HTNet * net;
|
|
|
|
HTNet * net;
|
|
|
|
HTTimer * timer;
|
|
|
|
HTTimer * timer;
|
|
|
|
} file_info;
|
|
|
|
} file_info;
|
|
|
|
|
|
|
|
|
|
|
|
struct _HTStream {
|
|
|
|
struct _HTStream {
|
|
|
|
const HTStreamClass * isa;
|
|
|
|
const HTStreamClass * isa;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct _HTInputStream {
|
|
|
|
struct _HTInputStream {
|
|
|
|
const HTInputStreamClass * isa;
|
|
|
|
const HTInputStreamClass * isa;
|
|
|
|
HTChannel * ch;
|
|
|
|
HTChannel * ch;
|
|
|
|
HTHost * host;
|
|
|
|
HTHost * host;
|
|
|
|
char * write; /* Last byte written */
|
|
|
|
char * write; /* Last byte written */
|
|
|
|
char * read; /* Last byte read */
|
|
|
|
char * read; /* Last byte read */
|
|
|
|
int b_read;
|
|
|
|
int b_read;
|
|
|
|
char data [INPUT_BUFFER_SIZE]; /* buffer */
|
|
|
|
char data [INPUT_BUFFER_SIZE]; /* buffer */
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
PRIVATE int FileCleanup (HTRequest *req, int status)
|
|
|
|
PRIVATE int FileCleanup (HTRequest *req, int status)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HTNet * net = HTRequest_net(req);
|
|
|
|
HTNet * net = HTRequest_net(req);
|
|
|
|
file_info * file = (file_info *) HTNet_context(net);
|
|
|
|
file_info * file = (file_info *) HTNet_context(net);
|
|
|
|
HTStream * input = HTRequest_inputStream(req);
|
|
|
|
HTStream * input = HTRequest_inputStream(req);
|
|
|
|
|
|
|
|
|
|
|
|
/* Free stream with data TO Local file system */
|
|
|
|
/* Free stream with data TO Local file system */
|
|
|
|
if (input)
|
|
|
|
if (input)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (status == HT_INTERRUPTED)
|
|
|
|
if (status == HT_INTERRUPTED)
|
|
|
|
(*input->isa->abort)(input, NULL);
|
|
|
|
(*input->isa->abort)(input, NULL);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
(*input->isa->_free)(input);
|
|
|
|
(*input->isa->_free)(input);
|
|
|
|
HTRequest_setInputStream(req, NULL);
|
|
|
|
HTRequest_setInputStream(req, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
** Remove if we have registered a timer function as a callback
|
|
|
|
** Remove if we have registered a timer function as a callback
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
if (file->timer)
|
|
|
|
if (file->timer)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HTTimer_delete(file->timer);
|
|
|
|
HTTimer_delete(file->timer);
|
|
|
|
file->timer = NULL;
|
|
|
|
file->timer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HT_FREE(file->local);
|
|
|
|
HT_FREE(file->local);
|
|
|
|
HT_FREE(file);
|
|
|
|
HT_FREE(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HTNet_delete(net, status);
|
|
|
|
HTNet_delete(net, status);
|
|
|
|
return YES;
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -122,104 +118,104 @@ PRIVATE int FileEvent (SOCKET soc, void * pVoid, HTEventType type);
|
|
|
|
|
|
|
|
|
|
|
|
PUBLIC int HTLoadNeLFile (SOCKET soc, HTRequest * request)
|
|
|
|
PUBLIC int HTLoadNeLFile (SOCKET soc, HTRequest * request)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
file_info *file; /* Specific access information */
|
|
|
|
file_info *file; /* Specific access information */
|
|
|
|
HTNet * net = HTRequest_net(request);
|
|
|
|
HTNet * net = HTRequest_net(request);
|
|
|
|
HTParentAnchor * anchor = HTRequest_anchor(request);
|
|
|
|
HTParentAnchor * anchor = HTRequest_anchor(request);
|
|
|
|
|
|
|
|
|
|
|
|
HTTRACE(PROT_TRACE, "HTLoadFile.. Looking for `%s\'\n" _
|
|
|
|
HTTRACE(PROT_TRACE, "HTLoadFile.. Looking for `%s\'\n" _
|
|
|
|
HTAnchor_physical(anchor));
|
|
|
|
HTAnchor_physical(anchor));
|
|
|
|
if ((file = (file_info *) HT_CALLOC(1, sizeof(file_info))) == NULL)
|
|
|
|
if ((file = (file_info *) HT_CALLOC(1, sizeof(file_info))) == NULL)
|
|
|
|
HT_OUTOFMEM((char*)"HTLoadFILE");
|
|
|
|
HT_OUTOFMEM((char*)"HTLoadFILE");
|
|
|
|
file->state = FS_BEGIN;
|
|
|
|
file->state = FS_BEGIN;
|
|
|
|
file->net = net;
|
|
|
|
file->net = net;
|
|
|
|
HTNet_setContext(net, file);
|
|
|
|
HTNet_setContext(net, file);
|
|
|
|
HTNet_setEventCallback(net, FileEvent);
|
|
|
|
HTNet_setEventCallback(net, FileEvent);
|
|
|
|
HTNet_setEventParam(net, file); /* callbacks get http* */
|
|
|
|
HTNet_setEventParam(net, file); /* callbacks get http* */
|
|
|
|
|
|
|
|
|
|
|
|
return FileEvent(soc, file, HTEvent_BEGIN); /* get it started - ops is ignored */
|
|
|
|
return FileEvent(soc, file, HTEvent_BEGIN); /* get it started - ops is ignored */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRIVATE int ReturnEvent (HTTimer * timer, void * param, HTEventType /* type */)
|
|
|
|
PRIVATE int ReturnEvent (HTTimer * timer, void * param, HTEventType /* type */)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
file_info * file = (file_info *) param;
|
|
|
|
file_info * file = (file_info *) param;
|
|
|
|
if (timer != file->timer)
|
|
|
|
if (timer != file->timer)
|
|
|
|
HTDEBUGBREAK((char*)"File timer %p not in sync\n" _ timer);
|
|
|
|
HTDEBUGBREAK((char*)"File timer %p not in sync\n" _ timer);
|
|
|
|
HTTRACE(PROT_TRACE, "HTLoadFile.. Continuing %p with timer %p\n" _ file _ timer);
|
|
|
|
HTTRACE(PROT_TRACE, "HTLoadFile.. Continuing %p with timer %p\n" _ file _ timer);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
** Delete the timer
|
|
|
|
** Delete the timer
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
HTTimer_delete(file->timer);
|
|
|
|
HTTimer_delete(file->timer);
|
|
|
|
file->timer = NULL;
|
|
|
|
file->timer = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
** Now call the event again
|
|
|
|
** Now call the event again
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
return FileEvent(INVSOC, file, HTEvent_READ);
|
|
|
|
return FileEvent(INVSOC, file, HTEvent_READ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PUBLIC int HTNeLFileOpen (HTNet * net, char * local, HTLocalMode /* mode */)
|
|
|
|
PUBLIC int HTNeLFileOpen (HTNet * net, char * local, HTLocalMode /* mode */)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HTRequest * request = HTNet_request(net);
|
|
|
|
HTRequest * request = HTNet_request(net);
|
|
|
|
HTHost * host = HTNet_host(net);
|
|
|
|
HTHost * host = HTNet_host(net);
|
|
|
|
CIFile* fp = new CIFile;
|
|
|
|
CIFile* fp = new CIFile;
|
|
|
|
|
|
|
|
|
|
|
|
if (!fp->open (local))
|
|
|
|
if (!fp->open (local))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HTRequest_addSystemError(request, ERR_FATAL, errno, NO, (char*)"CIFile::open");
|
|
|
|
HTRequest_addSystemError(request, ERR_FATAL, errno, NO, (char*)"CIFile::open");
|
|
|
|
return HT_ERROR;
|
|
|
|
return HT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HTHost_setChannel(host, HTChannel_new(INVSOC, (FILE*)fp, YES));
|
|
|
|
HTHost_setChannel(host, HTChannel_new(INVSOC, (FILE*)fp, YES));
|
|
|
|
|
|
|
|
|
|
|
|
HTHost_getInput(host, HTNet_transport(net), NULL, 0);
|
|
|
|
HTHost_getInput(host, HTNet_transport(net), NULL, 0);
|
|
|
|
HTHost_getOutput(host, HTNet_transport(net), NULL, 0);
|
|
|
|
HTHost_getOutput(host, HTNet_transport(net), NULL, 0);
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRIVATE int FileEvent (SOCKET /* soc */, void * pVoid, HTEventType type)
|
|
|
|
PRIVATE int FileEvent (SOCKET /* soc */, void * pVoid, HTEventType type)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
file_info *file = (file_info *)pVoid; /* Specific access information */
|
|
|
|
file_info *file = (file_info *)pVoid; /* Specific access information */
|
|
|
|
int status = HT_ERROR;
|
|
|
|
int status = HT_ERROR;
|
|
|
|
HTNet * net = file->net;
|
|
|
|
HTNet * net = file->net;
|
|
|
|
HTRequest * request = HTNet_request(net);
|
|
|
|
HTRequest * request = HTNet_request(net);
|
|
|
|
HTParentAnchor * anchor = HTRequest_anchor(request);
|
|
|
|
HTParentAnchor * anchor = HTRequest_anchor(request);
|
|
|
|
|
|
|
|
|
|
|
|
if (type == HTEvent_CLOSE)
|
|
|
|
if (type == HTEvent_CLOSE)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* Interrupted */
|
|
|
|
/* Interrupted */
|
|
|
|
HTRequest_addError(request, ERR_FATAL, NO, HTERR_INTERRUPTED,
|
|
|
|
HTRequest_addError(request, ERR_FATAL, NO, HTERR_INTERRUPTED,
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
FileCleanup(request, HT_INTERRUPTED);
|
|
|
|
FileCleanup(request, HT_INTERRUPTED);
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Now jump into the machine. We know the state from the previous run */
|
|
|
|
/* Now jump into the machine. We know the state from the previous run */
|
|
|
|
for(;;)
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch (file->state)
|
|
|
|
switch (file->state)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case FS_BEGIN:
|
|
|
|
case FS_BEGIN:
|
|
|
|
|
|
|
|
|
|
|
|
/* We only support safe (GET, HEAD, etc) methods for the moment */
|
|
|
|
/* We only support safe (GET, HEAD, etc) methods for the moment */
|
|
|
|
if (!HTMethod_isSafe(HTRequest_method(request))) {
|
|
|
|
if (!HTMethod_isSafe(HTRequest_method(request))) {
|
|
|
|
HTRequest_addError(request, ERR_FATAL, NO, HTERR_NOT_ALLOWED,
|
|
|
|
HTRequest_addError(request, ERR_FATAL, NO, HTERR_NOT_ALLOWED,
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
file->state = FS_ERROR;
|
|
|
|
file->state = FS_ERROR;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Check whether we have access to local disk at all */
|
|
|
|
/* Check whether we have access to local disk at all */
|
|
|
|
if (HTLib_secure())
|
|
|
|
if (HTLib_secure())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HTTRACE(PROT_TRACE, "LoadFile.... No access to local file system\n");
|
|
|
|
HTTRACE(PROT_TRACE, "LoadFile.... No access to local file system\n");
|
|
|
|
file->state = FS_TRY_FTP;
|
|
|
|
file->state = FS_TRY_FTP;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*file->local = HTWWWToLocal(HTAnchor_physical(anchor), "",
|
|
|
|
/*file->local = HTWWWToLocal(HTAnchor_physical(anchor), "",
|
|
|
|
HTRequest_userProfile(request));*/
|
|
|
|
HTRequest_userProfile(request));*/
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string tmp = HTAnchor_physical(anchor);
|
|
|
|
string tmp = HTAnchor_physical(anchor);
|
|
|
|
if (strlwr(tmp).find("file:/") == 0)
|
|
|
|
if (strlwr(tmp).find("file:/") == 0)
|
|
|
@ -229,70 +225,70 @@ PRIVATE int FileEvent (SOCKET /* soc */, void * pVoid, HTEventType type)
|
|
|
|
StrAllocCopy(file->local, tmp.c_str());
|
|
|
|
StrAllocCopy(file->local, tmp.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!file->local)
|
|
|
|
if (!file->local)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
file->state = FS_TRY_FTP;
|
|
|
|
file->state = FS_TRY_FTP;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Create a new host object and link it to the net object */
|
|
|
|
/* Create a new host object and link it to the net object */
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HTHost * host = NULL;
|
|
|
|
HTHost * host = NULL;
|
|
|
|
if ((host = HTHost_new((char*)"localhost", 0)) == NULL) return HT_ERROR;
|
|
|
|
if ((host = HTHost_new((char*)"localhost", 0)) == NULL) return HT_ERROR;
|
|
|
|
HTNet_setHost(net, host);
|
|
|
|
HTNet_setHost(net, host);
|
|
|
|
if (HTHost_addNet(host, net) == HT_PENDING) {
|
|
|
|
if (HTHost_addNet(host, net) == HT_PENDING) {
|
|
|
|
HTTRACE(PROT_TRACE, "HTLoadFile.. Pending...\n");
|
|
|
|
HTTRACE(PROT_TRACE, "HTLoadFile.. Pending...\n");
|
|
|
|
/* move to the hack state */
|
|
|
|
/* move to the hack state */
|
|
|
|
file->state = FS_PENDING;
|
|
|
|
file->state = FS_PENDING;
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file->state = FS_DO_CN;
|
|
|
|
file->state = FS_DO_CN;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case FS_PENDING:
|
|
|
|
case FS_PENDING:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HTHost * host = NULL;
|
|
|
|
HTHost * host = NULL;
|
|
|
|
if ((host = HTHost_new((char*)"localhost", 0)) == NULL) return HT_ERROR;
|
|
|
|
if ((host = HTHost_new((char*)"localhost", 0)) == NULL) return HT_ERROR;
|
|
|
|
HTNet_setHost(net, host);
|
|
|
|
HTNet_setHost(net, host);
|
|
|
|
if (HTHost_addNet(host, net) == HT_PENDING) {
|
|
|
|
if (HTHost_addNet(host, net) == HT_PENDING) {
|
|
|
|
HTTRACE(PROT_TRACE, "HTLoadFile.. Pending...\n");
|
|
|
|
HTTRACE(PROT_TRACE, "HTLoadFile.. Pending...\n");
|
|
|
|
file->state = FS_PENDING;
|
|
|
|
file->state = FS_PENDING;
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file->state = FS_DO_CN;
|
|
|
|
file->state = FS_DO_CN;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case FS_DO_CN:
|
|
|
|
case FS_DO_CN:
|
|
|
|
if (HTRequest_negotiation(request) &&
|
|
|
|
if (HTRequest_negotiation(request) &&
|
|
|
|
HTMethod_isSafe(HTRequest_method(request))) {
|
|
|
|
HTMethod_isSafe(HTRequest_method(request))) {
|
|
|
|
|
|
|
|
|
|
|
|
HTAnchor_setPhysical(anchor, file->local);
|
|
|
|
HTAnchor_setPhysical(anchor, file->local);
|
|
|
|
HTTRACE(PROT_TRACE, "Load File... Found `%s\'\n" _ file->local);
|
|
|
|
HTTRACE(PROT_TRACE, "Load File... Found `%s\'\n" _ file->local);
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (HT_STAT(file->local, &file->stat_info) == -1) {
|
|
|
|
if (HT_STAT(file->local, &file->stat_info) == -1) {
|
|
|
|
HTTRACE(PROT_TRACE, "Load File... Not found `%s\'\n" _ file->local);
|
|
|
|
HTTRACE(PROT_TRACE, "Load File... Not found `%s\'\n" _ file->local);
|
|
|
|
HTRequest_addError(request, ERR_FATAL, NO, HTERR_NOT_FOUND,
|
|
|
|
HTRequest_addError(request, ERR_FATAL, NO, HTERR_NOT_FOUND,
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
file->state = FS_ERROR;
|
|
|
|
file->state = FS_ERROR;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (((file->stat_info.st_mode) & S_IFMT) == S_IFDIR) {
|
|
|
|
if (((file->stat_info.st_mode) & S_IFMT) == S_IFDIR) {
|
|
|
|
if (HTRequest_method(request) == METHOD_GET)
|
|
|
|
if (HTRequest_method(request) == METHOD_GET)
|
|
|
|
file->state = FS_PARSE_DIR;
|
|
|
|
file->state = FS_PARSE_DIR;
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
HTRequest_addError(request, ERR_INFO, NO, HTERR_NO_CONTENT,
|
|
|
|
HTRequest_addError(request, ERR_INFO, NO, HTERR_NO_CONTENT,
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
file->state = FS_NO_DATA;
|
|
|
|
file->state = FS_NO_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BOOL editable = FALSE;
|
|
|
|
BOOL editable = FALSE;
|
|
|
|
HTBind_getAnchorBindings(anchor);
|
|
|
|
HTBind_getAnchorBindings(anchor);
|
|
|
|
if (editable) HTAnchor_appendAllow(anchor, METHOD_PUT);
|
|
|
|
if (editable) HTAnchor_appendAllow(anchor, METHOD_PUT);
|
|
|
@ -306,124 +302,124 @@ PRIVATE int FileEvent (SOCKET /* soc */, void * pVoid, HTEventType type)
|
|
|
|
nelFile.close();
|
|
|
|
nelFile.close();
|
|
|
|
|
|
|
|
|
|
|
|
if (file->stat_info.st_size)
|
|
|
|
if (file->stat_info.st_size)
|
|
|
|
HTAnchor_setLength(anchor, file->stat_info.st_size);
|
|
|
|
HTAnchor_setLength(anchor, file->stat_info.st_size);
|
|
|
|
|
|
|
|
|
|
|
|
/* Set the file last modified time stamp */
|
|
|
|
/* Set the file last modified time stamp */
|
|
|
|
if (file->stat_info.st_mtime > 0)
|
|
|
|
if (file->stat_info.st_mtime > 0)
|
|
|
|
HTAnchor_setLastModified(anchor, file->stat_info.st_mtime);
|
|
|
|
HTAnchor_setLastModified(anchor, file->stat_info.st_mtime);
|
|
|
|
|
|
|
|
|
|
|
|
/* Check to see if we can edit it */
|
|
|
|
/* Check to see if we can edit it */
|
|
|
|
if (!editable && !file->stat_info.st_size) {
|
|
|
|
if (!editable && !file->stat_info.st_size) {
|
|
|
|
HTRequest_addError(request, ERR_INFO, NO, HTERR_NO_CONTENT,
|
|
|
|
HTRequest_addError(request, ERR_INFO, NO, HTERR_NO_CONTENT,
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
file->state = FS_NO_DATA;
|
|
|
|
file->state = FS_NO_DATA;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
file->state = (HTRequest_method(request)==METHOD_GET) ?
|
|
|
|
file->state = (HTRequest_method(request)==METHOD_GET) ?
|
|
|
|
FS_NEED_OPEN_FILE : FS_GOT_DATA;
|
|
|
|
FS_NEED_OPEN_FILE : FS_GOT_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case FS_NEED_OPEN_FILE:
|
|
|
|
case FS_NEED_OPEN_FILE:
|
|
|
|
status = HTNeLFileOpen(net, file->local, HT_FB_RDONLY);
|
|
|
|
status = HTNeLFileOpen(net, file->local, HT_FB_RDONLY);
|
|
|
|
if (status == HT_OK) {
|
|
|
|
if (status == HT_OK) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HTStream * rstream = HTStreamStack(HTAnchor_format(anchor),
|
|
|
|
HTStream * rstream = HTStreamStack(HTAnchor_format(anchor),
|
|
|
|
HTRequest_outputFormat(request),
|
|
|
|
HTRequest_outputFormat(request),
|
|
|
|
HTRequest_outputStream(request),
|
|
|
|
HTRequest_outputStream(request),
|
|
|
|
request, YES);
|
|
|
|
request, YES);
|
|
|
|
HTNet_setReadStream(net, rstream);
|
|
|
|
HTNet_setReadStream(net, rstream);
|
|
|
|
HTRequest_setOutputConnected(request, YES);
|
|
|
|
HTRequest_setOutputConnected(request, YES);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HTOutputStream * output = HTNet_getOutput(net, NULL, 0);
|
|
|
|
HTOutputStream * output = HTNet_getOutput(net, NULL, 0);
|
|
|
|
HTRequest_setInputStream(request, (HTStream *) output);
|
|
|
|
HTRequest_setInputStream(request, (HTStream *) output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (HTRequest_isSource(request) && !HTRequest_destinationsReady(request))
|
|
|
|
if (HTRequest_isSource(request) && !HTRequest_destinationsReady(request))
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
HTRequest_addError(request, ERR_INFO, NO, HTERR_OK, NULL, 0,
|
|
|
|
HTRequest_addError(request, ERR_INFO, NO, HTERR_OK, NULL, 0,
|
|
|
|
(char*)"HTLoadFile");
|
|
|
|
(char*)"HTLoadFile");
|
|
|
|
file->state = FS_NEED_BODY;
|
|
|
|
file->state = FS_NEED_BODY;
|
|
|
|
|
|
|
|
|
|
|
|
if (HTEvent_isCallbacksRegistered()) {
|
|
|
|
if (HTEvent_isCallbacksRegistered()) {
|
|
|
|
if (!HTRequest_preemptive(request)) {
|
|
|
|
if (!HTRequest_preemptive(request)) {
|
|
|
|
if (!HTNet_preemptive(net)) {
|
|
|
|
if (!HTNet_preemptive(net)) {
|
|
|
|
HTTRACE(PROT_TRACE, "HTLoadFile.. Returning\n");
|
|
|
|
HTTRACE(PROT_TRACE, "HTLoadFile.. Returning\n");
|
|
|
|
HTHost_register(HTNet_host(net), net, HTEvent_READ);
|
|
|
|
HTHost_register(HTNet_host(net), net, HTEvent_READ);
|
|
|
|
} else if (!file->timer) {
|
|
|
|
} else if (!file->timer) {
|
|
|
|
HTTRACE(PROT_TRACE, "HTLoadFile.. Returning\n");
|
|
|
|
HTTRACE(PROT_TRACE, "HTLoadFile.. Returning\n");
|
|
|
|
file->timer =
|
|
|
|
file->timer =
|
|
|
|
HTTimer_new(NULL, ReturnEvent, file, 1, YES, NO);
|
|
|
|
HTTimer_new(NULL, ReturnEvent, file, 1, YES, NO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (status == HT_WOULD_BLOCK || status == HT_PENDING)
|
|
|
|
} else if (status == HT_WOULD_BLOCK || status == HT_PENDING)
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
HTRequest_addError(request, ERR_INFO, NO, HTERR_INTERNAL,
|
|
|
|
HTRequest_addError(request, ERR_INFO, NO, HTERR_INTERNAL,
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
file->state = FS_ERROR; /* Error or interrupt */
|
|
|
|
file->state = FS_ERROR; /* Error or interrupt */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case FS_NEED_BODY:
|
|
|
|
case FS_NEED_BODY:
|
|
|
|
status = HTHost_read(HTNet_host(net), net);
|
|
|
|
status = HTHost_read(HTNet_host(net), net);
|
|
|
|
if (status == HT_WOULD_BLOCK)
|
|
|
|
if (status == HT_WOULD_BLOCK)
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
else if (status == HT_LOADED || status == HT_CLOSED) {
|
|
|
|
else if (status == HT_LOADED || status == HT_CLOSED) {
|
|
|
|
file->state = FS_GOT_DATA;
|
|
|
|
file->state = FS_GOT_DATA;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
HTRequest_addError(request, ERR_INFO, NO, HTERR_FORBIDDEN,
|
|
|
|
HTRequest_addError(request, ERR_INFO, NO, HTERR_FORBIDDEN,
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
file->state = FS_ERROR;
|
|
|
|
file->state = FS_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case FS_TRY_FTP:
|
|
|
|
case FS_TRY_FTP:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char *url = HTAnchor_physical(anchor);
|
|
|
|
char *url = HTAnchor_physical(anchor);
|
|
|
|
HTAnchor *anchor;
|
|
|
|
HTAnchor *anchor;
|
|
|
|
char *newname = NULL;
|
|
|
|
char *newname = NULL;
|
|
|
|
StrAllocCopy(newname, "ftp:");
|
|
|
|
StrAllocCopy(newname, "ftp:");
|
|
|
|
if (!strncmp(url, "file:", 5))
|
|
|
|
if (!strncmp(url, "file:", 5))
|
|
|
|
StrAllocCat(newname, url+5);
|
|
|
|
StrAllocCat(newname, url+5);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
StrAllocCat(newname, url);
|
|
|
|
StrAllocCat(newname, url);
|
|
|
|
anchor = HTAnchor_findAddress(newname);
|
|
|
|
anchor = HTAnchor_findAddress(newname);
|
|
|
|
HTRequest_setAnchor(request, anchor);
|
|
|
|
HTRequest_setAnchor(request, anchor);
|
|
|
|
HT_FREE(newname);
|
|
|
|
HT_FREE(newname);
|
|
|
|
FileCleanup(request, HT_IGNORE);
|
|
|
|
FileCleanup(request, HT_IGNORE);
|
|
|
|
return HTLoad(request, YES);
|
|
|
|
return HTLoad(request, YES);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case FS_GOT_DATA:
|
|
|
|
case FS_GOT_DATA:
|
|
|
|
FileCleanup(request, HT_LOADED);
|
|
|
|
FileCleanup(request, HT_LOADED);
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case FS_NO_DATA:
|
|
|
|
case FS_NO_DATA:
|
|
|
|
FileCleanup(request, HT_NO_DATA);
|
|
|
|
FileCleanup(request, HT_NO_DATA);
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case FS_RETRY:
|
|
|
|
case FS_RETRY:
|
|
|
|
FileCleanup(request, HT_RETRY);
|
|
|
|
FileCleanup(request, HT_RETRY);
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case FS_ERROR:
|
|
|
|
case FS_ERROR:
|
|
|
|
FileCleanup(request, HT_ERROR);
|
|
|
|
FileCleanup(request, HT_ERROR);
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* End of while(1) */
|
|
|
|
} /* End of while(1) */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// *************************************************************************
|
|
|
|
// *************************************************************************
|
|
|
@ -440,12 +436,12 @@ size_t nel_fread (void *buffer, uint size, FILE *fp)
|
|
|
|
|
|
|
|
|
|
|
|
PRIVATE int HTNeLReader_read (HTInputStream * me)
|
|
|
|
PRIVATE int HTNeLReader_read (HTInputStream * me)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FILE * fp = HTChannel_file(me->ch);
|
|
|
|
FILE * fp = HTChannel_file(me->ch);
|
|
|
|
HTNet * net = HTHost_getReadNet(me->host);
|
|
|
|
HTNet * net = HTHost_getReadNet(me->host);
|
|
|
|
int status;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
|
|
/* Read the file desriptor */
|
|
|
|
/* Read the file desriptor */
|
|
|
|
while (fp)
|
|
|
|
while (fp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ((me->b_read = (int)nel_fread(me->data, FILE_BUFFER_SIZE, fp)) == 0)
|
|
|
|
if ((me->b_read = (int)nel_fread(me->data, FILE_BUFFER_SIZE, fp)) == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -492,9 +488,9 @@ PRIVATE int HTNeLReader_read (HTInputStream * me)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
me->write = me->data + me->b_read;
|
|
|
|
me->write = me->data + me->b_read;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HTTRACE(PROT_TRACE, "ANSI read... File descriptor is NULL...\n");
|
|
|
|
HTTRACE(PROT_TRACE, "ANSI read... File descriptor is NULL...\n");
|
|
|
|
return HT_ERROR;
|
|
|
|
return HT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRIVATE int HTNeLReader_close (HTInputStream * me)
|
|
|
|
PRIVATE int HTNeLReader_close (HTInputStream * me)
|
|
|
@ -505,32 +501,32 @@ PRIVATE int HTNeLReader_close (HTInputStream * me)
|
|
|
|
file->close();
|
|
|
|
file->close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int status = HT_OK;
|
|
|
|
int status = HT_OK;
|
|
|
|
HTNet * net = HTHost_getReadNet(me->host);
|
|
|
|
HTNet * net = HTHost_getReadNet(me->host);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (net && net->readStream) {
|
|
|
|
if (net && net->readStream) {
|
|
|
|
if ((status = (*net->readStream->isa->_free)(net->readStream))==HT_WOULD_BLOCK)
|
|
|
|
if ((status = (*net->readStream->isa->_free)(net->readStream))==HT_WOULD_BLOCK)
|
|
|
|
return HT_WOULD_BLOCK;
|
|
|
|
return HT_WOULD_BLOCK;
|
|
|
|
net->readStream = NULL;
|
|
|
|
net->readStream = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HTTRACE(STREAM_TRACE, "Socket read. FREEING....\n");
|
|
|
|
HTTRACE(STREAM_TRACE, "Socket read. FREEING....\n");
|
|
|
|
HT_FREE(me);
|
|
|
|
HT_FREE(me);
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PUBLIC int HTNeLReader_consumed (HTInputStream * me, size_t bytes)
|
|
|
|
PUBLIC int HTNeLReader_consumed (HTInputStream * me, size_t bytes)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
me->write += bytes;
|
|
|
|
me->write += bytes;
|
|
|
|
me->b_read -= (int)bytes;
|
|
|
|
me->b_read -= (int)bytes;
|
|
|
|
HTHost_setRemainingRead(me->host, me->b_read);
|
|
|
|
HTHost_setRemainingRead(me->host, me->b_read);
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRIVATE int HTNeLReader_flush (HTInputStream * me)
|
|
|
|
PRIVATE int HTNeLReader_flush (HTInputStream * me)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HTNet * net = HTHost_getReadNet(me->host);
|
|
|
|
HTNet * net = HTHost_getReadNet(me->host);
|
|
|
|
return net && net->readStream ? (*net->readStream->isa->flush)(net->readStream) : HT_OK;
|
|
|
|
return net && net->readStream ? (*net->readStream->isa->flush)(net->readStream) : HT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRIVATE int HTNeLReader_free (HTInputStream * me)
|
|
|
|
PRIVATE int HTNeLReader_free (HTInputStream * me)
|
|
|
@ -542,54 +538,56 @@ PRIVATE int HTNeLReader_free (HTInputStream * me)
|
|
|
|
HTChannel_setFile (me->ch, NULL);
|
|
|
|
HTChannel_setFile (me->ch, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HTNet * net = HTHost_getReadNet(me->host);
|
|
|
|
HTNet * net = HTHost_getReadNet(me->host);
|
|
|
|
if (net && net->readStream) {
|
|
|
|
if (net && net->readStream) {
|
|
|
|
int status = (*net->readStream->isa->_free)(net->readStream);
|
|
|
|
int status = (*net->readStream->isa->_free)(net->readStream);
|
|
|
|
if (status == HT_OK) net->readStream = NULL;
|
|
|
|
if (status == HT_OK) net->readStream = NULL;
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return HT_OK;
|
|
|
|
return HT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRIVATE int HTNeLReader_abort (HTInputStream * me, HTList * /* e */)
|
|
|
|
PRIVATE int HTNeLReader_abort (HTInputStream * me, HTList * /* e */)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HTNet * net = HTHost_getReadNet(me->host);
|
|
|
|
HTNet * net = HTHost_getReadNet(me->host);
|
|
|
|
if (net && net->readStream) {
|
|
|
|
if (net && net->readStream) {
|
|
|
|
int status = (*net->readStream->isa->abort)(net->readStream, NULL);
|
|
|
|
int status = (*net->readStream->isa->abort)(net->readStream, NULL);
|
|
|
|
if (status != HT_IGNORE) net->readStream = NULL;
|
|
|
|
if (status != HT_IGNORE) net->readStream = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return HT_ERROR;
|
|
|
|
return HT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRIVATE const HTInputStreamClass HTNeLReader =
|
|
|
|
PRIVATE const HTInputStreamClass HTNeLReader =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
(char*)"SocketReader",
|
|
|
|
(char*)"SocketReader",
|
|
|
|
HTNeLReader_flush,
|
|
|
|
HTNeLReader_flush,
|
|
|
|
HTNeLReader_free,
|
|
|
|
HTNeLReader_free,
|
|
|
|
HTNeLReader_abort,
|
|
|
|
HTNeLReader_abort,
|
|
|
|
HTNeLReader_read,
|
|
|
|
HTNeLReader_read,
|
|
|
|
HTNeLReader_close,
|
|
|
|
HTNeLReader_close,
|
|
|
|
HTNeLReader_consumed
|
|
|
|
HTNeLReader_consumed
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
PUBLIC HTInputStream * HTNeLReader_new (HTHost * host, HTChannel * ch,
|
|
|
|
PUBLIC HTInputStream * HTNeLReader_new (HTHost * host, HTChannel * ch,
|
|
|
|
void * /* param */, int /* mode */)
|
|
|
|
void * /* param */, int /* mode */)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (host && ch) {
|
|
|
|
if (host && ch) {
|
|
|
|
HTInputStream * me = HTChannel_input(ch);
|
|
|
|
HTInputStream * me = HTChannel_input(ch);
|
|
|
|
if (me == NULL) {
|
|
|
|
if (me == NULL) {
|
|
|
|
if ((me=(HTInputStream *) HT_CALLOC(1, sizeof(HTInputStream))) == NULL)
|
|
|
|
if ((me=(HTInputStream *) HT_CALLOC(1, sizeof(HTInputStream))) == NULL)
|
|
|
|
HT_OUTOFMEM((char*)"HTNeLReader_new");
|
|
|
|
HT_OUTOFMEM((char*)"HTNeLReader_new");
|
|
|
|
me->isa = &HTNeLReader;
|
|
|
|
me->isa = &HTNeLReader;
|
|
|
|
me->ch = ch;
|
|
|
|
me->ch = ch;
|
|
|
|
me->host = host;
|
|
|
|
me->host = host;
|
|
|
|
HTTRACE(STREAM_TRACE, "Reader...... Created reader stream %p\n" _ me);
|
|
|
|
HTTRACE(STREAM_TRACE, "Reader...... Created reader stream %p\n" _ me);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return me;
|
|
|
|
return me;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//PUBLIC unsigned int WWW_TraceFlag = 0;
|
|
|
|
//PUBLIC unsigned int WWW_TraceFlag = 0;
|
|
|
|
|
|
|
|
|
|
|
|
} // extern "C"
|
|
|
|
} // extern "C"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|