|
|
@ -89,7 +89,8 @@ PRIVATE int FileCleanup (HTRequest *req, int status)
|
|
|
|
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
|
|
|
@ -100,16 +101,19 @@ PRIVATE int FileCleanup (HTRequest *req, int status)
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
** 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);
|
|
|
|
{
|
|
|
|
file->timer = NULL;
|
|
|
|
HTTimer_delete(file->timer);
|
|
|
|
|
|
|
|
file->timer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (file) {
|
|
|
|
if (file)
|
|
|
|
HT_FREE(file->local);
|
|
|
|
{
|
|
|
|
HT_FREE(file);
|
|
|
|
HT_FREE(file->local);
|
|
|
|
|
|
|
|
HT_FREE(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HTNet_delete(net, status);
|
|
|
|
|
|
|
|
|
|
|
|
HTNet_delete(net, status);
|
|
|
|
return YES;
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -181,32 +185,37 @@ PRIVATE int FileEvent (SOCKET /* soc */, void * pVoid, HTEventType type)
|
|
|
|
HTRequest * request = HTNet_request(net);
|
|
|
|
HTRequest * request = HTNet_request(net);
|
|
|
|
HTParentAnchor * anchor = HTRequest_anchor(request);
|
|
|
|
HTParentAnchor * anchor = HTRequest_anchor(request);
|
|
|
|
|
|
|
|
|
|
|
|
if (type == HTEvent_CLOSE) { /* Interrupted */
|
|
|
|
if (type == HTEvent_CLOSE)
|
|
|
|
HTRequest_addError(request, ERR_FATAL, NO, HTERR_INTERRUPTED,
|
|
|
|
{
|
|
|
|
NULL, 0, "HTLoadFile");
|
|
|
|
/* Interrupted */
|
|
|
|
FileCleanup(request, HT_INTERRUPTED);
|
|
|
|
HTRequest_addError(request, ERR_FATAL, NO, HTERR_INTERRUPTED,
|
|
|
|
return HT_OK;
|
|
|
|
NULL, 0, "HTLoadFile");
|
|
|
|
|
|
|
|
FileCleanup(request, HT_INTERRUPTED);
|
|
|
|
|
|
|
|
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, "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");
|
|
|
|
{
|
|
|
|
file->state = FS_TRY_FTP;
|
|
|
|
HTTRACE(PROT_TRACE, "LoadFile.... No access to local file system\n");
|
|
|
|
break;
|
|
|
|
file->state = FS_TRY_FTP;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*file->local = HTWWWToLocal(HTAnchor_physical(anchor), "",
|
|
|
|
/*file->local = HTWWWToLocal(HTAnchor_physical(anchor), "",
|
|
|
@ -220,15 +229,16 @@ 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;
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
file->state = FS_TRY_FTP;
|
|
|
|
|
|
|
|
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("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");
|
|
|
@ -243,7 +253,7 @@ PRIVATE int FileEvent (SOCKET /* soc */, void * pVoid, HTEventType type)
|
|
|
|
case FS_PENDING:
|
|
|
|
case FS_PENDING:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HTHost * host = NULL;
|
|
|
|
HTHost * host = NULL;
|
|
|
|
if ((host = HTHost_new("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");
|
|
|
@ -265,7 +275,7 @@ PRIVATE int FileEvent (SOCKET /* soc */, void * pVoid, HTEventType type)
|
|
|
|
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, "HTLoadFile");
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
file->state = FS_ERROR;
|
|
|
|
file->state = FS_ERROR;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -276,7 +286,7 @@ PRIVATE int FileEvent (SOCKET /* soc */, void * pVoid, HTEventType type)
|
|
|
|
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, "HTLoadFile");
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
file->state = FS_NO_DATA;
|
|
|
|
file->state = FS_NO_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -305,7 +315,7 @@ PRIVATE int FileEvent (SOCKET /* soc */, void * pVoid, HTEventType type)
|
|
|
|
/* 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, "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) ?
|
|
|
@ -334,7 +344,7 @@ PRIVATE int FileEvent (SOCKET /* soc */, void * pVoid, HTEventType type)
|
|
|
|
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,
|
|
|
|
"HTLoadFile");
|
|
|
|
(char*)"HTLoadFile");
|
|
|
|
file->state = FS_NEED_BODY;
|
|
|
|
file->state = FS_NEED_BODY;
|
|
|
|
|
|
|
|
|
|
|
|
if (HTEvent_isCallbacksRegistered()) {
|
|
|
|
if (HTEvent_isCallbacksRegistered()) {
|
|
|
@ -354,7 +364,7 @@ PRIVATE int FileEvent (SOCKET /* soc */, void * pVoid, HTEventType type)
|
|
|
|
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, "HTLoadFile");
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
file->state = FS_ERROR; /* Error or interrupt */
|
|
|
|
file->state = FS_ERROR; /* Error or interrupt */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -367,7 +377,7 @@ PRIVATE int FileEvent (SOCKET /* soc */, void * pVoid, HTEventType type)
|
|
|
|
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, "HTLoadFile");
|
|
|
|
NULL, 0, (char*)"HTLoadFile");
|
|
|
|
file->state = FS_ERROR;
|
|
|
|
file->state = FS_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -550,7 +560,7 @@ PRIVATE int HTNeLReader_abort (HTInputStream * me, HTList * /* e */)
|
|
|
|
|
|
|
|
|
|
|
|
PRIVATE const HTInputStreamClass HTNeLReader =
|
|
|
|
PRIVATE const HTInputStreamClass HTNeLReader =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"SocketReader",
|
|
|
|
(char*)"SocketReader",
|
|
|
|
HTNeLReader_flush,
|
|
|
|
HTNeLReader_flush,
|
|
|
|
HTNeLReader_free,
|
|
|
|
HTNeLReader_free,
|
|
|
|
HTNeLReader_abort,
|
|
|
|
HTNeLReader_abort,
|
|
|
|