/* Deletes all the memory allocated in a parent anchor and returns any ** hyperdoc object hanging of this anchor */ PRIVATE void * delete_parent (HTParentAnchor * me) { void * doc = me->document; /* Remove link and address information */ if (me->links) { HTList *cur = me->links; HTLink *pres; while ((pres = (HTLink *) HTList_nextObject(cur))) HTLink_delete(pres); HTList_delete(me->links); } /* Remove children */ if (me->children) { int cnt = 0; for (; cnt<CHILD_HASH_SIZE; cnt++) { if (me->children[cnt]) HTList_delete(me->children[cnt]); } HT_FREE(me->children); } HTList_delete (me->sources); HTList_delete (me->variants); HT_FREE(me->physical); HT_FREE(me->address); /* Then remove entity header information (metainformation) */ HTAnchor_clearHeader(me); HT_FREE(me); return doc; }
/* Delete a parent anchor and all its children. If a hyperdoc object ** is found hanging off the parent anchor then this is returned */ PRIVATE void * delete_family (HTAnchor * me) { HTParentAnchor * parent = NULL; if (!me) { HTTRACE(ANCH_TRACE, "AnchorDelete No anchor found\n"); return NULL; } parent = me->parent; HTTRACE(ANCH_TRACE, "AnchorDelete Remove parent %p and children\n" _ parent); /* Delete children */ if (parent->children) { int cnt = 0; for (; cnt<CHILD_HASH_SIZE; cnt++) { HTList * kids = parent->children[cnt]; if (kids) { HTChildAnchor * child; while ((child=(HTChildAnchor*)HTList_removeLastObject(kids))) { HT_FREE(child->tag); if (child->links) { HTList * cur = child->links; HTLink * pres; while ((pres = (HTLink *) HTList_nextObject(cur))) HTLink_delete(pres); HTList_delete(child->links); } HT_FREE(child); } HTList_delete(kids); parent->children[cnt] = NULL; } } } return delete_parent(parent); }
PUBLIC BOOL HTResponse_delete (HTResponse * me) { if (me) { HTTRACE(CORE_TRACE, "Response.... Delete %p\n" _ me); /* Access Authentication */ HT_FREE(me->realm); HT_FREE(me->scheme); if (me->challenge) HTAssocList_delete(me->challenge); /* Connection headers */ if (me->connection) HTAssocList_delete(me->connection); /* PEP Information */ if (me->protocol) HTAssocList_delete(me->protocol); if (me->protocol_request) HTAssocList_delete(me->protocol_request); if (me->protocol_info) HTAssocList_delete(me->protocol_info); /* Cache control headers */ if (me->cache_control) HTAssocList_delete(me->cache_control); /* Byte ranges */ if (me->byte_ranges) HTAssocList_delete(me->byte_ranges); /* Transfer Encodings */ if (me->transfer_encoding) HTList_delete(me->transfer_encoding); /* Trailers */ if (me->trailer) HTAssocList_delete(me->trailer); /* Variants */ if (me->variants) HTAssocList_delete(me->variants); /* ** Only delete Content Type parameters and original headers if the ** information is not used elsewhere, for example by the anchor ** object. */ if (!me->cached) { /* Content type parameters */ if (me->type_parameters) HTAssocList_delete(me->type_parameters); /* Content Encodings */ if (me->content_encoding) HTList_delete(me->content_encoding); /* List of all headers */ if (me->headers) HTAssocList_delete(me->headers); } /* HTTP reason string */ if (me->reason) HT_FREE (me->reason); HT_FREE(me); return YES; } return NO; }
PRIVATE AddressDefList *parse_address_part ARGS1(FILE *, fp) { AddressDefList *address_def_list = NULL; LexItem lex_item; BOOL only_one = NO; lex_item = lex(fp); if (lex_item == LEX_ALPH_STR || lex_item == LEX_TMPL_STR) only_one = YES; else if (lex_item != LEX_OPEN_PAREN || ((lex_item = lex(fp)) != LEX_ALPH_STR && lex_item != LEX_TMPL_STR)) { syntax_error(fp, "Expecting a single address or '(' beginning list", lex_item); return NULL; } address_def_list = HTList_new(); for(;;) { Ref *ref = (Ref*)calloc(1, sizeof(Ref)); ref->name = NULL; ref->translation = NULL; StrAllocCopy(ref->name, HTlex_buffer); HTList_addObject(address_def_list, (void*)ref); if (only_one || (lex_item = lex(fp)) != LEX_ITEM_SEP) break; /* ** Here lex_item == LEX_ITEM_SEP; after item separator it ** is ok to have one or more newlines (LEX_REC_SEP) and ** they are ignored (continuation line). */ do { lex_item = lex(fp); } while (lex_item == LEX_REC_SEP); if (lex_item != LEX_ALPH_STR && lex_item != LEX_TMPL_STR) { syntax_error(fp, "Expecting an address template", lex_item); HTList_delete(address_def_list); address_def_list = NULL; return NULL; } } if (!only_one && lex_item != LEX_CLOSE_PAREN) { HTList_delete(address_def_list); address_def_list = NULL; syntax_error(fp, "Expecting ')' closing address list", lex_item); return NULL; } return address_def_list; }
/* ServerCleanup ** ------------- ** This function cleans up after the request ** Returns YES on OK, else NO */ PRIVATE int ServerCleanup (HTRequest * req, HTNet * net, int status) { https_info * http = (https_info *) HTNet_context(net); HTStream * input = HTRequest_inputStream(req); HTChannel * channel = HTNet_channel(net); /* Free stream with data TO network */ if (input) { if (status == HT_INTERRUPTED) (*input->isa->abort)(input, NULL); else (*input->isa->_free)(input); HTRequest_setInputStream(req, NULL); } /* Kill all remaining requests */ if (http->clients) { HTList * cur = http->clients; HTRequest * pres; while ((pres = HTList_nextObject(cur)) != NULL) HTRequest_kill(pres); HTList_delete(http->clients); } /* ** Remove the net object and our own context structure for http. ** Also unregister all pending requests and close the connection */ HTChannel_setSemaphore(channel, 0); HTNet_delete(net, HT_IGNORE); HT_FREE(http); return YES; }
char *Reference_List (Robot *mr) { HTList *copy = mr->urilist; char *output = NULL; char *number = malloc(sizeof("9999 :")); char *index = malloc(1000); int i = 1; int refs = HText_sourceAnchors(mr->htext); if (refs <= 0) { return("\n\nThere are no references from this document.\n\n"); } else { StrAllocCat(output, "List of references: \n"); sprintf(number, "%d total references\n", mr->count); while ((index = (char *) HTList_nextObject(copy))) { sprintf(number, "[%d] : ", i++); StrAllocCat(output, number); StrAllocCat(output, index); StrAllocCat(output, "\n"); HT_FREE(index); } HTList_delete(copy); return(output); } }
/* Delete a Command Line Object ** ---------------------------- */ PRIVATE BOOL Robot_delete (Robot * me) { if (me) { if (me->urilist) { HTList *cur = me->urilist; char *temp; while ((temp = (char *) HTList_nextObject(cur))) { HT_FREE(temp); } HTList_delete(cur); } if (me->htext) { HText_free(me->htext); } if (me->output && me->output != STDOUT) fclose(me->output); HT_FREE(me->cwd); HT_FREE(me->tv); /* Delete the profile */ #if 0 HTProfile_delete(); #endif HT_FREE(me); return YES; } return NO; }
/* ** Moves all link information from one anchor to another. ** This is used in redirection etc. ** Returns YES if OK, else NO */ PUBLIC BOOL HTLink_moveAll (HTAnchor * src, HTAnchor * dest) { if (!src || !dest) return NO; HTTRACE(ANCH_TRACE, "Link move... all from anchor %p to anchor %p\n" _ (void *) src _ (void *) dest); /* Move main link information */ dest->mainLink.dest = src->mainLink.dest; dest->mainLink.type = src->mainLink.type; dest->mainLink.method = src->mainLink.method; dest->mainLink.result = src->mainLink.result; src->mainLink.dest = NULL; src->mainLink.type = NULL; src->mainLink.method = METHOD_INVALID; src->mainLink.result = HT_LINK_INVALID; /* Move link information for other links */ if (dest->links) { HTList *cur = dest->links; HTLink *pres; while ((pres = (HTLink *) HTList_nextObject(cur))) HT_FREE(pres); HTList_delete(dest->links); } dest->links = src->links; src->links = NULL; return YES; }
PRIVATE ItemList *parse_item_list ARGS1(FILE *, fp) { ItemList *item_list = HTList_new(); Item *item; LexItem lex_item; for(;;) { if (!(item = parse_item(fp))) { HTList_delete(item_list); /* @@@@ */ item_list = NULL; return NULL; } HTList_addObject(item_list, (void*)item); lex_item = lex(fp); if (lex_item != LEX_ITEM_SEP) { unlex(lex_item); return item_list; } /* ** Here lex_item == LEX_ITEM_SEP; after item separator it ** is ok to have one or more newlines (LEX_REC_SEP) and ** they are ignored (continuation line). */ do { lex_item = lex(fp); } while (lex_item == LEX_REC_SEP); unlex(lex_item); } }
/* ** Unregister all sockets ** N.B. we just remove them for our internal data structures: it is up to the ** application to actually close the socket. */ PUBLIC int HTEventList_unregisterAll (void) { int i; HTTRACE(THD_TRACE, "Unregister.. all sockets\n"); for (i = 0 ; i < HT_M_HASH_SIZE; i++) { HTList * cur = HashTable[i]; SockEvents * pres; while ((pres = (SockEvents *) HTList_nextObject(cur))) { #ifdef WWW_WIN_ASYNC WSAAsyncSelect(pres->s, HTSocketWin, HTwinMsg, 0); #endif /* WWW_WIN_ASYNC */ HT_FREE(pres); } HTList_delete(HashTable[i]); HashTable[i] = NULL; } #ifndef WWW_WIN_ASYNC MaxSock = 0 ; HTTRACE(THD_TRACE, "Event....... New value for MaxSock is %d\n" _ MaxSock); FD_ZERO(FdArray+HTEvent_INDEX(HTEvent_READ)); FD_ZERO(FdArray+HTEvent_INDEX(HTEvent_WRITE)); FD_ZERO(FdArray+HTEvent_INDEX(HTEvent_OOB)); #endif /* !WWW_WIN_ASYNC */ EventOrder_deleteAll(); return 0; }
PUBLIC BOOL EventOrder_deleteAll (void) { EventOrder_clearAll(); HTList_delete(EventOrderList); EventOrderList = NULL; return YES; }
/* Clear Header Information ** ------------------------ */ PUBLIC void HTAnchor_clearHeader (HTParentAnchor * me) { HTTRACE(ANCH_TRACE, "HTAnchor.... Clear all header information\n"); me->allow = METHOD_INVALID; if (me->content_encoding) { HTList_delete(me->content_encoding); me->content_encoding = NULL; } if (me->content_language) { HTList_delete(me->content_language); me->content_language = NULL; } HT_FREE(me->content_base); HT_FREE(me->content_location); me->content_length = -1; /* Invalid */ /* Delete the title */ HT_FREE(me->title); /* Clear the content type */ me->content_type = WWW_UNKNOWN; if (me->type_parameters) { HTAssocList_delete(me->type_parameters); me->type_parameters = NULL; } /* Meta tags */ if (me->meta_tags) { HTAssocList_delete(me->meta_tags); me->meta_tags = NULL; } /* Dates etc. */ me->date = (time_t) -1; me->expires = (time_t) -1; me->last_modified = (time_t) -1; me->age = (time_t) -1; HT_FREE(me->derived_from); HT_FREE(me->version); HT_FREE(me->etag); /* Delete any original headers */ if (me->headers) HTAssocList_delete(me->headers); me->headers = NULL; }
PUBLIC BOOL HTAnchor_deleteEncodingAll (HTParentAnchor * me) { if (me && me->content_encoding) { HTList_delete(me->content_encoding); me->content_encoding = NULL; return YES; } return NO; }
/* HTNoProxy_deleteAll ** ------------------- ** Removes all registered no_proxy directives */ PUBLIC BOOL HTNoProxy_deleteAll (void) { if (remove_AllHostnames(noproxy)) { HTList_delete(noproxy); noproxy = NULL; return YES; } return NO; }
PRIVATE BOOL HTNewsNode_delete (HTNewsNode * node, BOOL cache) { if (node) { if (!cache || node->is_tmplate) HT_FREE(node->name); HT_FREE(node->subject); HT_FREE(node->from); if (node->refNames) { HTList * cur = node->refNames; char * pres; while ((pres = (char *) HTList_nextObject(cur))) HT_FREE(pres); HTList_delete(node->refNames); } if (node->refObjects) HTList_delete(node->refObjects); HT_FREE(node); return YES; } return NO; }
PUBLIC BOOL HTAnchor_deleteLanguageAll (HTParentAnchor * me) { if (me && me->content_language) { HTList_delete(me->content_language); me->content_language = NULL; return YES; } return NO; }
/* ** Removes all registered gateways */ PUBLIC BOOL HTGateway_deleteAll (void) { if (remove_allObjects(gateways)) { HTList_delete(gateways); gateways = NULL; return YES; } return NO; }
PUBLIC void HTCoding_deleteAll (HTList * list) { if (list) { HTList * cur = list; HTCoding * pres; while ((pres = (HTCoding *) HTList_nextObject(cur))) HT_FREE(pres); HTList_delete(list); } }
PUBLIC BOOL CSUserList_destroy(void) { char * userName; while ((userName = (char *) HTList_removeLastObject(UserList))) HT_FREE(userName); HTList_delete(UserList); UserList = NULL; return YES; }
/* HTMemoryCall_deleteAll ** ---------------------- ** Unregisters all call back functions */ PUBLIC BOOL HTMemoryCall_deleteAll (void) { HTTRACE(MEM_TRACE, "Mem Delete.. All Callback functions\n"); if (HTMemCall) { HTList_delete(HTMemCall); HTMemCall = NULL; return YES; } return NO; }
PUBLIC void HTFreeDescriptions (HTList * descriptions) { HTList * cur = descriptions; char * str; if (descriptions) { while ((str = (char*)HTList_nextObject(cur))) HT_FREE(str); HTList_delete(descriptions); } }
PUBLIC void HTCharset_deleteAll (HTList * list) { if (list) { HTList *cur = list; HTAcceptNode *pres; while ((pres = (HTAcceptNode *) HTList_nextObject(cur))) { HT_FREE(pres); } HTList_delete(list); } }
/* ** Free all registered hypertext documents in memory */ PUBLIC BOOL HText_freeAll (void) { if (loaded_texts) { HTList * cur = loaded_texts; HText * pres; while ((pres = (HText *) HTList_nextObject(cur))) HText_free(pres); HTList_delete(loaded_texts); return YES; } return NO; }
/* ------------------------------------------------------------------------- This function replaces the code in HTRequest_delete() in order to keep the data structure hidden (it is NOT a joke!) Henrik 14/03-94 ------------------------------------------------------------------------- */ PUBLIC void HTFormatDelete ARGS1(HTList *, me) { HTList *cur = me; HTPresentation *pres; if (!me) return; while ((pres = (HTPresentation*) HTList_nextObject(cur))) { FREE(pres->command); /* Leak fixed AL 6 Feb 1994 */ free(pres); } HTList_delete(me); /* Leak fixed AL 6 Feb 1994 */ }
PUBLIC void HTPresentation_deleteAll (HTList * list) { if (list) { HTList *cur = list; HTPresentation *pres; while ((pres = (HTPresentation*) HTList_nextObject(cur))) { HT_FREE(pres->command); HT_FREE(pres); } HTList_delete(list); } }
PUBLIC BOOL HTStyleSheet_delete (HTStyleSheet * me) { if (me) { HTList * cur = me->styles; HTStyle * pres; while ((pres = (HTStyle *) HTList_nextObject(cur))) HTStyle_delete(pres); HTList_delete(me->styles); HT_FREE(me); return YES; } return NO; }
PUBLIC BOOL HTAA_deleteAllModules (void) { if (HTSchemes) { HTList * cur = HTSchemes; HTAAModule * pres; while ((pres = (HTAAModule *) HTList_nextObject(cur))) delete_module(pres); HTList_delete(HTSchemes); HTSchemes = NULL; return YES; } return NO; }
/* HTErrorFree ** ** Free the whole error stack from the HTRequest structure. */ PUBLIC void HTErrorFree ARGS1(HTRequest *, request) { HTList *cur = request->error_stack; HTErrorInfo *pres; if (!request || !request->error_stack) return; while ((pres = (HTErrorInfo *) HTList_nextObject(cur))) { FREE(pres->par); free(pres); } HTList_delete(request->error_stack); request->error_stack = NULL; return; }
/* Delete all rules ** ---------------- ** Deletes all the rules registered by this module */ PUBLIC BOOL HTRule_deleteAll (HTList * list) { if (list) { HTList *cur = list; HTRule *pres; while ((pres = (HTRule *) HTList_nextObject(cur))) { HT_FREE(pres->pattern); HT_FREE(pres->replace); HT_FREE(pres); } return HTList_delete(list); } return NO; }
PRIVATE BOOL HTCookieHolder_deleteAll (void) { if (cookie_holder) { HTList * cur = cookie_holder; HTCookieHolder * pres = NULL; while ((pres = (HTCookieHolder *) HTList_nextObject(cur))) { HTCookieHolder_delete(pres); } HTList_delete(cookie_holder); cookie_holder = NULL; return YES; } return NO; }