version 1.167, 1999/01/27 08:42:25
|
version 1.168, 1999/01/29 13:54:21
|
Line 22
|
Line 22
|
#ifndef _WINDOWS |
#ifndef _WINDOWS |
#endif /* !_WINDOWS */ |
#endif /* !_WINDOWS */ |
#define AMAYA_WWW_CACHE |
#define AMAYA_WWW_CACHE |
|
#define AMAYA_LOST_UPDATE |
|
|
#define CACHE_DIR_NAME DIR_STR"libwww-cache" |
#define CACHE_DIR_NAME DIR_STR"libwww-cache" |
#define DEFAULT_CACHE_SIZE 5 |
#define DEFAULT_CACHE_SIZE 5 |
Line 788 void *context;
|
Line 789 void *context;
|
int status; |
int status; |
#endif /* __STDC__ */ |
#endif /* __STDC__ */ |
{ |
{ |
AHTReqContext *me = (AHTReqContext *) HTRequest_context (request); |
AHTReqContext *me = (AHTReqContext *) HTRequest_context (request); |
int conflict = 0; |
HTAlertCallback *prompt = HTAlert_find (HT_A_CONFIRM); |
|
boolean force_put; |
|
char *tmp_buf; |
|
|
if (!me) |
if (!me) |
return HT_OK; /* not an Amaya request */ |
return HT_OK; /* not an Amaya request */ |
|
|
if (me->output && me->output != stdout) |
if (prompt) |
{ |
force_put = (*prompt) (request, HT_A_CONFIRM, HT_MSG_RULES, |
fclose (me->output); |
NULL, NULL, NULL); |
me->output = NULL; |
else |
} |
force_put = NO; |
|
|
if (conflict == 1) |
if (force_put) |
{ |
{ |
/* start a new PUT request without preconditions */ |
/* start a new PUT request without preconditions */ |
/* @@@ put some form here */ |
/* @@ do we need to kill the request? */ |
/* Stop here */ |
if (me->output && me->output != stdout) |
return HT_ERROR; |
{ |
} |
fclose (me->output); |
else |
me->output = NULL; |
if (conflict == 2) |
} |
{ |
/* turn off preconditions */ |
/* Stop here */ |
HTRequest_setPreconditions(me->request, HT_NO_MATCH); |
return HT_ERROR; |
/* |
} |
** reset the Amaya and libwww request status |
else |
*/ |
return HT_OK; /* Just finish the request */ |
me->reqStatus = HT_NEW; |
} |
/* clear the errors */ |
|
HTError_deleteAll (HTRequest_error (request)); |
|
HTRequest_setError (request, NULL); |
|
/* make the request */ |
|
status = HTPutDocumentAnchor (HTAnchor_parent (me->source), me->dest, me->request); |
|
/* stop here */ |
|
return HT_ERROR; |
|
} |
|
else |
|
{ |
|
/* abort the request */ |
|
/* @@ should we call StopRequest here? */ |
|
me->reqStatus = HT_ABORT; |
|
/* stop here */ |
|
return HT_ERROR; |
|
} |
|
} |
|
|
/* |
/*---------------------------------------------------------------------- |
** Request HEAD checker filter |
check_handler |
*/ |
Request HEAD checker filter |
PRIVATE int check_handler (HTRequest * request, HTResponse * response, |
----------------------------------------------------------------------*/ |
|
static int check_handler (HTRequest * request, HTResponse * response, |
void * param, int status) |
void * param, int status) |
{ |
{ |
int conflict = 0; |
AHTReqContext *me = (AHTReqContext *) HTRequest_context (request); |
/*** |
HTAlertCallback *prompt = HTAlert_find (HT_A_CONFIRM); |
CRequest * req = (CRequest *) HTRequest_context(request); |
boolean force_put; |
CVersionConflict conflict; |
char *tmp_buf; |
|
|
req->Cleanup(); |
if (!me) |
***/ |
return HT_OK; /* not an Amaya request */ |
/* |
|
** If head request showed that the document doesn't exist |
HTRequest_deleteAfter(me->request, check_handler); |
** then just go ahead and PUT it. Otherwise ask for help |
/* |
*/ |
** If head request showed that the document doesn't exist |
if (status==HT_INTERRUPTED || status==HT_TIMEOUT) |
** then just go ahead and PUT it. Otherwise ask for help |
{ |
*/ |
return HT_ERROR; |
if (status == HT_ERROR || status == HT_INTERRUPTED || status == HT_TIMEOUT) |
} |
{ |
else |
/* we'd need to call terminate_handler, to free the resources */ |
if (abs(status)/100!=2) |
/* abort the request */ |
|
/* @@ should we call StopRequest here? */ |
|
me->reqStatus = HT_ABORT; |
|
/* stop here */ |
|
return HT_ERROR; |
|
} |
|
else if (status == HT_NO_ACCESS || status == HT_NO_PROXY_ACCESS) |
|
{ |
|
/* we'd need to call terminate_handler, to free the resources */ |
|
/* abort the request */ |
|
/* @@ should we call StopRequest here? */ |
|
me->reqStatus = HT_ABORT; |
|
/* stop here */ |
|
return HT_ERROR; |
|
} |
|
else if ( (abs(status)/100) != 2) |
|
{ |
|
/* it's a new ressource, so we start a new PUT request with a |
|
"if-none-match *" precondition */ |
|
HTRequest_setPreconditions(me->request, HT_DONT_MATCH_ANY); |
|
status = HTPutDocumentAnchor (HTAnchor_parent (me->source), me->dest, me->request); |
|
return HT_ERROR; /* stop here */ |
|
} |
|
else |
|
{ |
|
if (prompt) |
|
force_put = (*prompt) (request, HT_A_CONFIRM, HT_MSG_FILE_REPLACE, |
|
NULL, NULL, NULL); |
|
else |
|
force_put = FALSE; |
|
|
|
if (force_put) |
{ |
{ |
/* Start a new PUT request without preconditions */ |
/* Start a new PUT request without preconditions */ |
/*** |
HTRequest_setPreconditions(me->request, HT_NO_MATCH); |
HTAnchor * source = req->Source(); |
status = HTPutDocumentAnchor (HTAnchor_parent (me->source), me->dest, me->request); |
HTAnchor * dest = req->Destination(); |
return HT_ERROR; /* stop here */ |
CRequest * new_req = new CRequest(req->m_pDoc); |
|
delete req; |
|
new_req->PutDocument(source, dest, FALSE); |
|
***/ |
|
} |
} |
else |
else |
if (conflict) |
{ |
{ |
/* we'd need to call terminate_handler, to free the resources */ |
if (conflict == 1) |
/* abort the request */ |
{ |
/* @@ should we call StopRequest here? */ |
/*** |
me->reqStatus = HT_ABORT; |
HTAnchor * source = req->Source(); |
/* stop here */ |
HTAnchor * dest = req->Destination(); |
return HT_ERROR; |
CRequest * new_req = new CRequest(req->m_pDoc); |
} |
delete req; |
} |
***/ |
return HT_ERROR; |
/* Start a new PUT request without preconditions */ |
|
/*** |
|
new_req->PutDocument(source, dest, FALSE); |
|
***/ |
|
} |
|
else |
|
if (conflict == 2) |
|
{ |
|
/*** |
|
HTAnchor * address = req->Source(); |
|
CRequest * new_req = new CRequest(req->m_pDoc); |
|
delete req; |
|
***/ |
|
/* Start a new GET request */ |
|
/*** |
|
new_req->GetDocument(address, 2); |
|
***/ |
|
} |
|
} |
|
return HT_ERROR; |
|
} |
} |
#endif /* AMAYA_LOST_UPDATE */ |
#endif /* AMAYA_LOST_UPDATE */ |
|
|
Line 1274 static void AHTProtocolInit (voi
|
Line 1301 static void AHTProtocolInit (voi
|
#endif |
#endif |
|
|
/* initialize pipelining */ |
/* initialize pipelining */ |
strptr = (char *) TtaGetEnvString ("USE_PIPELINING"); |
strptr = (char *) TtaGetEnvString ("ENABLE_PIPELINING"); |
if (strptr && *strptr && strcasecmp (strptr,"yes" )) |
if (strptr && *strptr && strcasecmp (strptr,"yes" )) |
HTTP_setConnectionMode (HTTP_11_NO_PIPELINING); |
HTTP_setConnectionMode (HTTP_11_NO_PIPELINING); |
} |
} |
Line 1318 static void AHTNetInit (void)
|
Line 1345 static void AHTNetInit (void)
|
HT_FILTER_MIDDLE); |
HT_FILTER_MIDDLE); |
HTNet_addAfter (redirection_handler, "http://*", NULL, HT_TEMP_REDIRECT, |
HTNet_addAfter (redirection_handler, "http://*", NULL, HT_TEMP_REDIRECT, |
HT_FILTER_MIDDLE); |
HT_FILTER_MIDDLE); |
|
HTNet_addAfter(HTAuthInfoFilter, "http://*", NULL, HT_ALL, |
|
HT_FILTER_MIDDLE); |
HTNet_addAfter (HTUseProxyFilter, "http://*", NULL, HT_USE_PROXY, |
HTNet_addAfter (HTUseProxyFilter, "http://*", NULL, HT_USE_PROXY, |
HT_FILTER_MIDDLE); |
HT_FILTER_MIDDLE); |
#ifdef AMAYA_WWW_CACHE |
#ifdef AMAYA_WWW_CACHE |
Line 2522 void *context_tcbf;
|
Line 2551 void *context_tcbf;
|
int fd; |
int fd; |
struct stat file_stat; |
struct stat file_stat; |
char *fileURL; |
char *fileURL; |
/* temporarily put it here, should come in the API */ |
char *etag = NULL; |
boolean UsePreconditions = FALSE; |
int UsePreconditions; |
|
|
|
UsePreconditions = mode & AMAYA_USE_PRECONDITIONS; |
|
|
AmayaLastHTTPErrorMsg [0] = EOS; |
AmayaLastHTTPErrorMsg [0] = EOS; |
|
|
Line 2569 void *context_tcbf;
|
Line 2600 void *context_tcbf;
|
} |
} |
|
|
/* prepare the request context */ |
/* prepare the request context */ |
|
|
if (THD_TRACE) |
if (THD_TRACE) |
fprintf (stderr, "file size == %u\n", (unsigned) file_stat.st_size); |
fprintf (stderr, "file size == %u\n", (unsigned) file_stat.st_size); |
|
|
me = AHTReqContext_new (docid); |
me = AHTReqContext_new (docid); |
|
|
if (me == NULL) |
if (me == NULL) |
{ |
{ |
/* @@ need an error message here */ |
/* @@ need an error message here */ |
TtaHandlePendingEvents (); |
TtaHandlePendingEvents (); |
return (HT_ERROR); |
return (HT_ERROR); |
} |
} |
Line 2598 void *context_tcbf;
|
Line 2627 void *context_tcbf;
|
|
|
#ifdef _WINDOWS |
#ifdef _WINDOWS |
/* libwww's HTParse function doesn't take into account the drive name; |
/* libwww's HTParse function doesn't take into account the drive name; |
so we sidestep it */ |
so we sidestep it */ |
fileURL = NULL; |
fileURL = NULL; |
StrAllocCopy (fileURL, "file:"); |
StrAllocCopy (fileURL, "file:"); |
StrAllocCat (fileURL, fileName); |
StrAllocCat (fileURL, fileName); |
#else |
#else |
fileURL = HTParse (fileName, "file:/", PARSE_ALL); |
fileURL = HTParse (fileName, "file:/", PARSE_ALL); |
#endif /* _WINDOWS */ |
#endif /* _WINDOWS */ |
me->anchor = (HTParentAnchor *) HTAnchor_findAddress (fileURL); |
me->source = HTAnchor_findAddress (fileURL); |
HT_FREE (fileURL); |
HT_FREE (fileURL); |
|
|
|
me->dest = HTAnchor_findAddress (urlName); |
|
|
/* Set the Content-Type of the file we are uploading */ |
/* Set the Content-Type of the file we are uploading */ |
HTAnchor_setFormat ((HTParentAnchor *) me->anchor, |
HTAnchor_setFormat (HTAnchor_parent (me->source), |
|
AHTGuessAtom_for (me->urlName, contentType)); |
|
HTAnchor_setFormat (HTAnchor_parent (me->dest), |
AHTGuessAtom_for (me->urlName, contentType)); |
AHTGuessAtom_for (me->urlName, contentType)); |
|
|
/* associate the anchor to the request */ |
/* associate the anchor to the request */ |
HTRequest_setEntityAnchor (me->request, me->anchor); |
HTRequest_setEntityAnchor (me->request, HTAnchor_parent (me->source)); |
|
|
/* define other request characteristics */ |
/* define other request characteristics */ |
#ifdef _WINDOWS |
#ifdef _WINDOWS |
Line 2628 void *context_tcbf;
|
Line 2661 void *context_tcbf;
|
*/ |
*/ |
if (mode & AMAYA_FLUSH_REQUEST) |
if (mode & AMAYA_FLUSH_REQUEST) |
HTRequest_setFlush(me->request, YES); |
HTRequest_setFlush(me->request, YES); |
|
|
/* Should we use preconditions? */ |
/* Should we use preconditions? */ |
if (UsePreconditions) |
if (UsePreconditions) |
HTRequest_setPreconditions(me->request, YES); |
etag = HTAnchor_etag (HTAnchor_parent (me->dest)); |
|
|
|
if (etag) |
|
{ |
|
HTRequest_setPreconditions(me->request, HT_MATCH_THIS); |
|
} |
|
else |
|
{ |
|
HTRequest_setPreconditions(me->request, HT_NO_MATCH); |
|
HTRequest_addAfter(me->request, check_handler, NULL, NULL, HT_ALL, |
|
HT_FILTER_MIDDLE, YES); |
|
} |
|
|
/* don't use the cache while saving a document */ |
/* don't use the cache while saving a document */ |
HTRequest_setReloadMode (me->request, HT_CACHE_FLUSH); |
HTRequest_setReloadMode (me->request, HT_CACHE_FLUSH); |
Line 2641 void *context_tcbf;
|
Line 2685 void *context_tcbf;
|
HTRequest_setOutputStream (me->request, HTBlackHole()); |
HTRequest_setOutputStream (me->request, HTBlackHole()); |
*/ |
*/ |
|
|
/* prepare the URLname that will be displayed in teh status bar */ |
/* prepare the URLname that will be displayed in the status bar */ |
ChopURL (me->status_urlName, me->urlName); |
ChopURL (me->status_urlName, me->urlName); |
TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REMOTE_SAVING), |
TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REMOTE_SAVING), |
me->status_urlName); |
me->status_urlName); |
|
|
/* make the request */ |
/* make the request */ |
status = HTPutDocumentAbsolute (me->anchor, urlName, me->request); |
if (!UsePreconditions || !etag) |
|
status = HTHeadAnchor (me->dest, me->request); |
|
else |
|
status = HTPutDocumentAnchor (HTAnchor_parent (me->source), me->dest, me->request); |
|
|
if (status == YES && me->reqStatus != HT_ERR) |
if (status == YES && me->reqStatus != HT_ERR) |
{ |
{ |
/* part of the stop button handler */ |
/* part of the stop button handler */ |
if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC)) |
if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC)) |
status = LoopForStop (me); |
status = LoopForStop (me); |
} |
} |
if (!HTRequest_kill (me->request)) |
if (!HTRequest_kill (me->request)) |
AHTReqContext_delete (me); |
AHTReqContext_delete (me); |
|
|
TtaHandlePendingEvents (); |
TtaHandlePendingEvents (); |
|
|
return (status == YES ? 0 : -1); |
return (status == YES ? 0 : -1); |