📄 htaccess.c
字号:
** -------------------------------------------** Upload a document referenced by a relative URL appended.** The URL can NOT contain any fragment identifier!** The list of form data must be given as an association list where ** the name is the field name and the value is the value of the field.*/PUBLIC BOOL HTPutRelative (HTParentAnchor * source, const char * relative, HTParentAnchor * destination_base, HTRequest * request){ if (source && relative && destination_base && request) { BOOL status; char * full_url = NULL; char * base_url = HTAnchor_address((HTAnchor *) destination_base); full_url=HTParse(relative, base_url, PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION); status = HTPutAbsolute(source, full_url, request); HT_FREE(full_url); HT_FREE(base_url); return status; } return NO;}/* Send an Anchor using PUT from an anchor** ---------------------------------------** Upload a document referenced by an anchor object appended** The URL can NOT contain any fragment identifier!** The list of form data must be given as an association list where ** the name is the field name and the value is the value of the field.*/PUBLIC BOOL HTPutAnchor (HTParentAnchor * source, HTAnchor * destination, HTRequest * request){ HTParentAnchor * dest = HTAnchor_parent(destination); if (source && dest && request) { if (setup_anchors(request, source, dest, METHOD_PUT) == YES) { /* Set up the request object */ HTRequest_addGnHd(request, HT_G_DATE); HTRequest_setEntityAnchor(request, source); HTRequest_setMethod(request, METHOD_PUT); HTRequest_setAnchor(request, destination); /* Setup preconditions */ set_preconditions(request); /* Add the entity callback function to provide the form data */ HTRequest_setPostCallback(request, HTEntity_callback); /* Now start the load normally */ return launch_request(request, NO); } } return NO;}/* Send an Anchor using POST from absolute name** -------------------------------------------** Upload a document referenced by an absolute URL appended.** The URL can NOT contain any fragment identifier!** The list of form data must be given as an association list where ** the name is the field name and the value is the value of the field.*/PUBLIC BOOL HTPostAbsolute (HTParentAnchor * source, const char * destination, HTRequest * request){ if (source && destination && request) { HTAnchor * dest = HTAnchor_findAddress(destination); return HTPostAnchor(source, dest, request); } return NO;}/* Send an Anchor using POST from relative name** -------------------------------------------** Upload a document referenced by a relative URL appended.** The URL can NOT contain any fragment identifier!** The list of form data must be given as an association list where ** the name is the field name and the value is the value of the field.*/PUBLIC BOOL HTPostRelative (HTParentAnchor * source, const char * relative, HTParentAnchor * destination_base, HTRequest * request){ if (source && relative && destination_base && request) { BOOL status; char * full_url = NULL; char * base_url = HTAnchor_address((HTAnchor *) destination_base); full_url=HTParse(relative, base_url, PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION); status = HTPostAbsolute(source, full_url, request); HT_FREE(full_url); HT_FREE(base_url); return status; } return NO;}/* Send an Anchor using POST from an anchor** ---------------------------------------** Upload a document referenced by an anchor object appended** The URL can NOT contain any fragment identifier!** The list of form data must be given as an association list where ** the name is the field name and the value is the value of the field.*/PUBLIC BOOL HTPostAnchor (HTParentAnchor * source, HTAnchor * destination, HTRequest * request){ HTParentAnchor * dest = HTAnchor_parent(destination); if (source && dest && request) { if (setup_anchors(request, source, dest, METHOD_POST) == YES) { /* Set up the request object */ HTRequest_addGnHd(request, HT_G_DATE); HTRequest_setEntityAnchor(request, source); HTRequest_setMethod(request, METHOD_POST); HTRequest_setAnchor(request, destination); /* Add the entity callback function to provide the form data */ HTRequest_setPostCallback(request, HTEntity_callback); /* Now start the load normally */ return launch_request(request, NO); } } return NO;}/* Send an Anchor using PUT from absolute name** -------------------------------------------** Upload a document referenced by an absolute URL appended.** The URL can NOT contain any fragment identifier!** The list of form data must be given as an association list where ** the name is the field name and the value is the value of the field.*/PUBLIC BOOL HTPutStructuredAbsolute (HTParentAnchor * source, const char * destination, HTRequest * request, HTPostCallback * input){ if (source && destination && request && input) { HTAnchor * dest = HTAnchor_findAddress(destination); return HTPutStructuredAnchor(source, dest, request, input); } return NO;}/* Send an Anchor using PUT from relative name** -------------------------------------------** Upload a document referenced by a relative URL appended.** The URL can NOT contain any fragment identifier!** The list of form data must be given as an association list where ** the name is the field name and the value is the value of the field.*/PUBLIC BOOL HTPutStructuredRelative (HTParentAnchor * source, const char * relative, HTParentAnchor * destination_base, HTRequest * request, HTPostCallback * input){ if (source && relative && destination_base && request && input) { BOOL status; char * full_url = NULL; char * base_url = HTAnchor_address((HTAnchor *) destination_base); full_url=HTParse(relative, base_url, PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION); status = HTPutStructuredAbsolute(source, full_url, request, input); HT_FREE(full_url); HT_FREE(base_url); return status; } return NO;}/* Send an Anchor using PUT from an anchor** ---------------------------------------** Upload a document referenced by an anchor object appended** The URL can NOT contain any fragment identifier!** The list of form data must be given as an association list where ** the name is the field name and the value is the value of the field.*/PUBLIC BOOL HTPutStructuredAnchor (HTParentAnchor * source, HTAnchor * destination, HTRequest * request, HTPostCallback * input){ HTParentAnchor * dest = HTAnchor_parent(destination); if (source && dest && request) { if (setup_anchors(request, source, dest, METHOD_PUT) == YES) { /* Set up the request object */ HTRequest_addGnHd(request, HT_G_DATE); HTRequest_setEntityAnchor(request, source); HTRequest_setMethod(request, METHOD_PUT); HTRequest_setAnchor(request, destination); /* Setup preconditions */ set_preconditions(request); /* Add the entity callback function to provide the form data */ HTRequest_setPostCallback(request, input); /* Now start the load normally */ return launch_request(request, NO); } } return NO;}/*** After filter for handling PUT of document.*/PRIVATE int HTSaveFilter (HTRequest * request, HTResponse * response, void * param, int status){ HTPutContext * me = (HTPutContext *) param; HTTRACE(APP_TRACE, "Save Filter. Using context %p with state %c\n" _ me _ me->state+0x30); /* ** Just ignore authentication in the hope that some other filter will ** handle this. */ if (status == HT_NO_ACCESS || status == HT_NO_PROXY_ACCESS || status == HT_REAUTH || status == HT_PROXY_REAUTH) { HTTRACE(APP_TRACE, "Save Filter. Waiting for authentication\n"); return HT_OK; } /* ** If either the source or the destination has moved then ask the user ** what to do. If there is no user then stop */ if (status == HT_TEMP_REDIRECT || status == HT_PERM_REDIRECT || status == HT_FOUND || status == HT_SEE_OTHER) { HTAlertCallback * prompt = HTAlert_find(HT_A_CONFIRM); HTAnchor * redirection = HTResponse_redirection(response); if (prompt && redirection) { if (me->state == HT_LOAD_SOURCE) { if ((*prompt)(request, HT_A_CONFIRM, HT_MSG_SOURCE_MOVED, NULL, NULL, NULL) == YES) { me->source = HTAnchor_parent(redirection); } else { /* ** Make sure that the operation stops */ me->state = HT_ABORT_SAVE; } } else {#if 0 /* ** If you are very precautios then you can ask here whether ** we should continue or not in case of a redirection */ if ((*prompt)(request, HT_A_CONFIRM, HT_MSG_DESTINATION_MOVED, NULL, NULL, NULL) == YES) { me->destination = redirection; } else { /* ** Make sure that the operation stops */ me->state = HT_ABORT_SAVE; }#else HTTRACE(APP_TRACE, "Save Filter. Destination hae moved!\n"); me->destination = redirection;#endif } } return HT_OK; } /* ** If we succeeded getting the source then start the PUT itself. Otherwise ** cleanup the mess */ if (me->state == HT_LOAD_SOURCE && (status == HT_LOADED || status == HT_NOT_MODIFIED) && !HTError_hasSeverity(HTRequest_error(request), ERR_INFO)) { /* Swap the document in the anchor with the new one */ me->placeholder = HTAnchor_document(me->source); HTAnchor_setDocument(me->source, HTChunk_data(me->document)); /* Set up the request object */ HTRequest_addGnHd(request, HT_G_DATE); HTRequest_setEntityAnchor(request, me->source); HTRequest_setMethod(request, METHOD_PUT); HTRequest_setAnchor(request, me->destination); HTRequest_setOutputFormat(request, me->format); HTRequest_setOutputStream(request, me->target); /* Set up preconditions */ set_preconditions(request); /* Delete existing credentials as they are generated anew */ HTRequest_deleteCredentialsAll(request); /* Make sure we flush the output immediately */ HTRequest_forceFlush(request); /* Turn progress notifications back on */ HTRequest_setInternal(request, NO); /* Add the entity callback function to provide the form data */ HTRequest_setPostCallback(request, HTEntity_callback); /* Now start the load normally */ if (launch_request(request, NO) == YES) me->state = HT_SAVE_DEST; else { HTAnchor_setDocument(me->source, me->placeholder); HTChunk_delete(me->document); HT_FREE(me); }#if 0 me->state = launch_request(request, NO) ? HT_SAVE_DEST : HT_LOAD_SOURCE;#endif /* ** By returning HT_ERROR we make sure that this is the last handler to ** be called. We do this as we don't want any other filter to delete ** the request object now when we have just started a new one ** ourselves */ return HT_ERROR; } else { HTAnchor_setDocument(me->source, me->placeholder); HTChunk_delete(me->document); HT_FREE(me); } return HT_OK;}/* Send an Anchor using PUT from absolute name** -------------------------------------------** Upload a document referenced by an absolute URL appended.** The URL can NOT contain any fragment identifier!** The list of form data must be given as an association list where ** the name is the field name and the value is the value of the field.*/PUBLIC BOOL HTPutDocumentAbsolute (HTParentAnchor * source, const char * destination, HTRequest * request){ if (source && destination && request) { HTAnchor * dest = HTAnchor_findAddress(destination); return HTPutDocumentAnchor(source, dest, request); } return NO;}/* Send an Anchor using PUT from relative name** -------------------------------------------** Upload a document referenced by a relative URL appended.** The URL can NOT contain any fragment identifier!** The list of form data must be given as an association list where ** the name is the field name and the value is the value of the field.*/PUBLIC BOOL HTPutDocumentRelative (HTParentAnchor * source, const char * relative, HTParentAnchor * destination_base, HTRequest * request){ if (source && relative && destination_base && request) { BOOL status; char * full_url = NULL; char * base_url = HTAnchor_address((HTAnchor *) destination_base); full_url=HTParse(relative, base_url, PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION); status = HTPutDocumentAbsolute(source, full_url, request); HT_FREE(full_url); HT_FREE(base_url); return status; } return NO;}/* Send an Anchor using PUT from an anchor** ---------------------------------------** Upload a document referenced by an anchor object appended** The URL can NOT contain any fragment identifier!** The source document is first loaded into memory and then the PUT** to the remote server is done using the memory version*/PUBLIC BOOL HTPutDocumentAnchor (HTParentAnchor * source, HTAnchor * destination, HTRequest * request){ HTParentAnchor * dest = HTAnchor_parent(destination); if (source && dest && request) { if (setup_anchors(request, source, dest, METHOD_PUT) == YES) { HTPutContext * context = NULL; /* ** First we register an AFTER filter that can check the result ** of the source load if success then it can start the PUT ** operation to the destination. */ if (!(context=(HTPutContext *) HT_CALLOC(1, sizeof(HTPutContext)))) HT_OUTOFMEM("HTPutDocumentAnchor"); context->source = source; context->destination = destination; /* ** We register the after filter with a NULL template as we ** don't know the source of the data. */ HTRequest_addAfter(request, HTSaveFilter, NULL, context, HT_ALL, HT_FILTER_FIRST, NO); /* Turn off progress notifications */ HTRequest_setInternal(request, YES); /* ** We make sure that we are not using a memory cached element. ** It's OK to use a file cached element! */ HTRequest_setReloadMode(request, HT_CACHE_FLUSH_MEM); /* ** Now we load the source document into a chunk. We specify that ** we want the document ASIS from the source location. */ context->format = HTRequest_outputFormat(request); context->target = HTRequest_outputStream(request); HTRequest_setOutputFormat(request, WWW_SOURCE); context->document = HTLoadAnchorToChunk((HTAnchor*)source,request); if (context->document == NULL) { HTTRACE(APP_TRACE, "Put Document No source\n"); HT_FREE(context); return NO; } return YES; } } return NO;}/* ------------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -