📄 htaccess.c
字号:
/* Copy an anchor** --------------** Fetch the URL (possibly local file URL) and send it using either PUT** or POST to the remote destination using HTTP. The caller can decide the** exact method used and which HTTP header fields to transmit by setting** the user fields in the request structure.** If posting to NNTP then we can't dispatch at this level but must pass** the source anchor to the news module that then takes all the refs** to NNTP and puts into the "newsgroups" header*/PUBLIC BOOL HTCopyAnchor (HTAnchor * src_anchor, HTRequest * main_dest){ HTRequest * src_req; HTList * cur; if (!src_anchor || !main_dest) { HTTRACE(APP_TRACE, "Copy........ BAD ARGUMENT\n"); return NO; } /* Set the source anchor */ main_dest->source_anchor = HTAnchor_parent(src_anchor); /* Build the POST web if not already there */ if (!main_dest->source) { src_req = HTRequest_dupInternal(main_dest); /* Get a duplicate */ HTAnchor_clearHeader((HTParentAnchor *) src_anchor); src_req->method = METHOD_GET; src_req->reload = HT_CACHE_FLUSH_MEM; src_req->output_stream = NULL; src_req->output_format = WWW_SOURCE; /* We want source (for now) */ /* Set up the main link in the source anchor */ { HTLink * main_link = HTAnchor_mainLink((HTAnchor *) src_anchor); HTAnchor *main_anchor = HTLink_destination(main_link); HTMethod method = HTLink_method(main_link); if (!main_link || method==METHOD_INVALID) { HTTRACE(APP_TRACE, "Copy Anchor. No destination found or unspecified method\n"); HTRequest_delete(src_req); return NO; } main_dest->GenMask |= HT_G_DATE; /* Send date header */ main_dest->reload = HT_CACHE_VALIDATE; main_dest->method = method; main_dest->input_format = WWW_SOURCE; HTRequest_addDestination(src_req, main_dest); if (HTLoadAnchor(main_anchor, main_dest) == NO) return NO; } /* For all other links in the source anchor */ if ((cur = HTAnchor_subLinks(src_anchor))) { HTLink * pres; while ((pres = (HTLink *) HTList_nextObject(cur))) { HTAnchor *dest = HTLink_destination(pres); HTMethod method = HTLink_method(pres); HTRequest *dest_req; if (!dest || method==METHOD_INVALID) { HTTRACE(APP_TRACE, "Copy Anchor. Bad anchor setup %p\n" _ dest); return NO; } dest_req = HTRequest_dupInternal(main_dest); dest_req->GenMask |= HT_G_DATE; /* Send date header */ dest_req->reload = HT_CACHE_VALIDATE; dest_req->method = method; dest_req->output_stream = NULL; dest_req->output_format = WWW_SOURCE; HTRequest_addDestination(src_req, dest_req); if (HTLoadAnchor(dest, dest_req) == NO) return NO; } } } else { /* Use the existing Post Web and restart it */ src_req = main_dest->source; if (src_req->mainDestination) if (launch_request(main_dest, NO) == NO) return NO; if (src_req->destinations) { HTRequest * pres; cur = HTAnchor_subLinks(src_anchor); while ((pres = (HTRequest *) HTList_nextObject(cur)) != NULL) { if (launch_request(pres, NO) == NO) return NO; } } } /* Now open the source */ return HTLoadAnchor(src_anchor, src_req);}/* Upload an Anchor** ----------------** This function can be used to send data along with a request to a remote** server. It can for example be used to POST form data to a remote HTTP** server - or it can be used to post a newsletter to a NNTP server. In** either case, you pass a callback function which the request calls when** the remote destination is ready to accept data. In this callback** you get the current request object and a stream into where you can ** write data. It is very important that you return the value returned** by this stream to the Library so that it knows what to do next. The** reason is that the outgoing stream might block or an error may** occur and in that case the Library must know about it. The source** anchor represents the data object in memory and it points to ** the destination anchor by using the POSTWeb method. The source anchor** contains metainformation about the data object in memory and the ** destination anchor represents the reponse from the remote server.** Returns YES if request accepted, else NO*/PUBLIC BOOL HTUploadAnchor (HTAnchor * source_anchor, HTRequest * request, HTPostCallback * callback){ HTLink * link = HTAnchor_mainLink((HTAnchor *) source_anchor); HTAnchor * dest_anchor = HTLink_destination(link); HTMethod method = HTLink_method(link); if (!link || method==METHOD_INVALID || !callback) { HTTRACE(APP_TRACE, "Upload...... No destination found or unspecified method\n"); return NO; } request->GenMask |= HT_G_DATE; /* Send date header */ request->reload = HT_CACHE_VALIDATE; request->method = method; request->source_anchor = HTAnchor_parent(source_anchor); request->PostCallback = callback; return HTLoadAnchor(dest_anchor, request);}/* POST Callback Handler** ---------------------** If you do not want to handle the stream interface on your own, you** can use this function which writes the source anchor hyperdoc to the** target stream for the anchor upload and also handles the return value** from the stream. If you don't want to write the source anchor hyperdoc** then you can register your own callback function that can get the data** you want.*/PUBLIC int HTUpload_callback (HTRequest * request, HTStream * target){ HTTRACE(APP_TRACE, "Uploading... from callback function\n"); if (!request || !request->source_anchor || !target) return HT_ERROR; { int status; HTParentAnchor * source = request->source_anchor; char * document = (char *) HTAnchor_document(request->source_anchor); int len = HTAnchor_length(source); if (len < 0) { len = strlen(document); HTAnchor_setLength(source, len); } status = (*target->isa->put_block)(target, document, len); if (status == HT_OK) return (*target->isa->flush)(target); if (status == HT_WOULD_BLOCK) { HTTRACE(PROT_TRACE, "POST Anchor. Target WOULD BLOCK\n"); return HT_WOULD_BLOCK; } else if (status == HT_PAUSE) { HTTRACE(PROT_TRACE, "POST Anchor. Target PAUSED\n"); return HT_PAUSE; } else if (status > 0) { /* Stream specific return code */ HTTRACE(PROT_TRACE, "POST Anchor. Target returns %d\n" _ status); return status; } else { /* we have a real error */ HTTRACE(PROT_TRACE, "POST Anchor. Target ERROR\n"); return status; } }}/* ------------------------------------------------------------------------- *//* HEAD METHOD *//* ------------------------------------------------------------------------- *//* Request metainformation about a document from absolute name** -----------------------------------------------------------** Request a document referencd by an absolute URL.** Returns YES if request accepted, else NO*/PUBLIC BOOL HTHeadAbsolute (const char * url, HTRequest * request){ if (url && request) { HTAnchor * anchor = HTAnchor_findAddress(url); return HTHeadAnchor(anchor, request); } return NO;}/* Request metainformation about a document from relative name** -----------------------------------------------------------** Request a document referenced by a relative URL. The relative URL is ** made absolute by resolving it relative to the address of the 'base' ** anchor.** Returns YES if request accepted, else NO*/PUBLIC BOOL HTHeadRelative (const char * relative, HTParentAnchor * base, HTRequest * request){ BOOL status = NO; if (relative && base && request) { char * rel = NULL; char * full_url = NULL; char * base_url = HTAnchor_address((HTAnchor *) base); StrAllocCopy(rel, relative); full_url = HTParse(HTStrip(rel), base_url, PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION); status = HTHeadAbsolute(full_url, request); HT_FREE(rel); HT_FREE(full_url); HT_FREE(base_url); } return status;}/* Request metainformation about an anchor** --------------------------------------** Request the document referenced by the anchor** Returns YES if request accepted, else NO*/PUBLIC BOOL HTHeadAnchor (HTAnchor * anchor, HTRequest * request){ if (anchor && request) { HTRequest_setAnchor(request, anchor); HTRequest_setMethod(request, METHOD_HEAD); return launch_request(request, NO); } return NO;}/* ------------------------------------------------------------------------- *//* DELETE METHOD *//* ------------------------------------------------------------------------- *//* Delete a document on a remote server** ------------------------------------** Request a document referencd by an absolute URL.** Returns YES if request accepted, else NO*/PUBLIC BOOL HTDeleteAbsolute (const char * url, HTRequest * request){ if (url && request) { HTAnchor * anchor = HTAnchor_findAddress(url); return HTDeleteAnchor(anchor, request); } return NO;}/* Request metainformation about a document from relative name** -----------------------------------------------------------** Request a document referenced by a relative URL. The relative URL is ** made absolute by resolving it relative to the address of the 'base' ** anchor.** Returns YES if request accepted, else NO*/PUBLIC BOOL HTDeleteRelative (const char * relative, HTParentAnchor * base, HTRequest * request){ BOOL status = NO; if (relative && base && request) { char * rel = NULL; char * full_url = NULL; char * base_url = HTAnchor_address((HTAnchor *) base); StrAllocCopy(rel, relative); full_url = HTParse(HTStrip(rel), base_url, PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION); status = HTDeleteAbsolute(full_url, request); HT_FREE(rel); HT_FREE(full_url); HT_FREE(base_url); } return status;}/* Request metainformation about an anchor** --------------------------------------** Request the document referenced by the anchor** Returns YES if request accepted, else NO*/PUBLIC BOOL HTDeleteAnchor (HTAnchor * anchor, HTRequest * request){ if (anchor && request) { HTRequest_setAnchor(request, anchor); HTRequest_setMethod(request, METHOD_DELETE); return launch_request(request, NO); } return NO;}/* ------------------------------------------------------------------------- *//* OPTIONS METHOD *//* ------------------------------------------------------------------------- *//* Options availeble for document from absolute name** -------------------------------------------------** Request a document referencd by an absolute URL.** Returns YES if request accepted, else NO*/PUBLIC BOOL HTOptionsAbsolute (const char * url, HTRequest * request){ if (url && request) { HTAnchor * anchor = HTAnchor_findAddress(url); return HTOptionsAnchor(anchor, request); } return NO;}/* Options available for document from relative name** -------------------------------------------------** Request a document referenced by a relative URL. The relative URL is ** made absolute by resolving it relative to the address of the 'base' ** anchor.** Returns YES if request accepted, else NO*/PUBLIC BOOL HTOptionsRelative (const char * relative, HTParentAnchor * base, HTRequest * request){ BOOL status = NO; if (relative && base && request) { char * rel = NULL; char * full_url = NULL; char * base_url = HTAnchor_address((HTAnchor *) base); StrAllocCopy(rel, relative); full_url = HTParse(HTStrip(rel), base_url, PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION); status = HTOptionsAbsolute(full_url, request); HT_FREE(rel); HT_FREE(full_url); HT_FREE(base_url); } return status;}/* Options available for document using Anchor** -------------------------------------------** Request the document referenced by the anchor** Returns YES if request accepted, else NO*/PUBLIC BOOL HTOptionsAnchor (HTAnchor * anchor, HTRequest * request){ if (anchor && request) { HTRequest_setAnchor(request, anchor); HTRequest_setMethod(request, METHOD_OPTIONS); return launch_request(request, NO); } return NO;}/* ------------------------------------------------------------------------- *//* TRACE METHOD *//* ------------------------------------------------------------------------- *//* Traces available for document from absolute name** ------------------------------------------------** Request a document referencd by an absolute URL.** Returns YES if request accepted, else NO*/PUBLIC BOOL HTTraceAbsolute (const char * url, HTRequest * request){ if (url && request) { HTAnchor * anchor = HTAnchor_findAddress(url); return HTTraceAnchor(anchor, request); } return NO;}/* Traces available for document from relative name** ------------------------------------------------** Request a document referenced by a relative URL. The relative URL is ** made absolute by resolving it relative to the address of the 'base' ** anchor.** Returns YES if request accepted, else NO*/PUBLIC BOOL HTTraceRelative (const char * relative, HTParentAnchor * base, HTRequest * request){ BOOL status = NO; if (relative && base && request) { char * rel = NULL; char * full_url = NULL; char * base_url = HTAnchor_address((HTAnchor *) base); StrAllocCopy(rel, relative); full_url = HTParse(HTStrip(rel), base_url, PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION); status = HTTraceAbsolute(full_url, request); HT_FREE(rel); HT_FREE(full_url); HT_FREE(base_url); } return status;}/* Trace available for document using Anchor** -------------------------------------------** Request the document referenced by the anchor** Returns YES if request accepted, else NO*/PUBLIC BOOL HTTraceAnchor (HTAnchor * anchor, HTRequest * request){ if (anchor && request) { HTRequest_setAnchor(request, anchor); HTRequest_setMethod(request, METHOD_TRACE); return launch_request(request, NO); } return NO;}/* ------------------------------------------------------------------------- *//* SERVER METHODS *//* ------------------------------------------------------------------------- */PRIVATE BOOL launch_server (HTRequest * request, BOOL recursive){#ifdef HTDEBUG if (PROT_TRACE) { HTParentAnchor *anchor = HTRequest_anchor(request); char * full_address = HTAnchor_address((HTAnchor *) anchor); HTTRACE(PROT_TRACE, "HTAccess.... Serving %s\n" _ full_address); HT_FREE(full_address); }#endif /* HTDEBUG */ return HTServe(request, recursive);}/* Serving a request** -----------------** Returns YES if request accepted, else NO*/PUBLIC BOOL HTServeAbsolute (const char * url, HTRequest * request){ if (url && request) { HTAnchor * anchor = HTAnchor_findAddress(url); HTRequest_setAnchor(request, anchor); return launch_server(request, NO); } return NO;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -