PRIVATE int terminate_handler (HTRequest * request, HTResponse * response, void * param, int status) { HTParentAnchor * anchor = HTRequest_anchor(request); HTAssocList * headers = HTAnchor_header(anchor); /* ** Write out the remaining list of headers that we not already store ** in the index file. */ if (headers) { HTAssocList * cur = headers; HTAssoc * pres; while ((pres = (HTAssoc *) HTAssocList_nextObject(cur))) { char * name = HTAssoc_name(pres); char * value = HTAssoc_value(pres); /* Now see if we have a match for this header field */ if (match && HTStrCaseMatch(match, name)) HTPrint("%s: %s\n", name, value); } } /* stop the event loop */ HTEventList_stopLoop (); /* stop here */ return HT_ERROR; }
/* Translate by rules ** ------------------ ** The most recently defined rules are applied last. ** This function walks through the list of rules and translates the ** reference when matches are found. The list is traversed in order ** starting from the head of the list. It returns the address of the ** equivalent string allocated from the heap which the CALLER MUST ** FREE. */ PUBLIC char * HTRule_translate (HTList * list, const char * token, BOOL ignore_case) { HTRule * pres; char * replace = NULL; if (!token || !list) return NULL; HTTRACE(APP_TRACE, "Check rules. for `%s\'\n" _ token); while ((pres = (HTRule *) HTList_nextObject(list))) { char * rest = ignore_case ? HTStrCaseMatch(pres->pattern, token) : HTStrMatch(pres->pattern, token); if (!rest) continue; /* No match at all */ /* We found a match for this entry, now do operation */ switch (pres->op) { case HT_Pass: case HT_Map: if (!pres->replace) { /* No replace */ StrAllocCopy(replace, token); } else if (*rest && pres->insert >= 0) { if ((replace = (char *) HT_MALLOC(strlen(pres->replace)+strlen(rest))) == NULL) HT_OUTOFMEM("HTRule_translate"); strcpy(replace, pres->replace); strcpy(replace+pres->insert, rest); } else { /* Perfect match or no insetion point */ StrAllocCopy(replace, pres->replace); } if (pres->op == HT_Pass) { HTTRACE(APP_TRACE, "............ map into `%s'\n" _ replace); return replace; } break; case HT_Fail: default: HTTRACE(APP_TRACE, "............ FAIL `%s'\n" _ token); return NULL; } } if (!replace) StrAllocCopy(replace, token); return replace; }
/* ** Search registered parsers to find suitable one for this token ** If a parser isn't found, the function returns HT_OK */ PUBLIC int HTMIMEParseSet_dispatch (HTMIMEParseSet * me, HTRequest * request, char * token, char * value, BOOL * pFound) { int hash; HTResponse * response = HTRequest_response(request); HTMIMEParseEl * pEl; if (pFound) *pFound = NO; /* ** Get a hash value for this token. This has is a function of the hash ** size given when the MIME header parse set was created. */ hash = HTMIMEParseSet_hash(me, token); /* ** Search for an exact match */ for (pEl = me->parsers[hash]; pEl; pEl = pEl->next) { if ((pEl->caseSensitive && !strcmp(pEl->token, token)) || (!pEl->caseSensitive && !strcasecomp(pEl->token, token))) { if (pFound) *pFound = YES; if (!pEl->pFunk) return HT_OK; /* registered with no callback*/ return (*pEl->pFunk)(request, response, token, value); } } /* ** Search for best match using regular expressions. */ for (pEl = me->regexParsers; pEl; pEl = pEl->next) { if ((pEl->caseSensitive && HTStrMatch(pEl->token, token)) || (!pEl->caseSensitive && HTStrCaseMatch(pEl->token, token))) { if (pFound) *pFound = YES; if (!pEl->pFunk) return HT_OK; /* registered with no callback*/ return (*pEl->pFunk)(request, response, token, value); } } return HT_OK; }
/* ** Runs through a sorted list of news groups and identifies the group ** hierarchy. Template groups are added to the list, for example as ** "alt.*" */ PRIVATE void HTNewsDir_setGroupInfo (HTNewsDir * dir) { HTArray * array = dir->array; HTNewsNode * node; int cur_size = HTArray_size(array); int cnt; /* ** If we don't have a template to test against then create one ** A template can be something like "alt.*" for example */ for (cnt=0; cnt<cur_size; cnt++) { node = (HTNewsNode *) HTArray_data(array)[cnt]; /* ** Make a template if we don't have any */ if (!dir->tmplate) make_template(dir, node); /* ** Now, if we do have a template then test the node name against ** it to see if we have this group already or it is a new group ** at this level in the hierarchy */ if (dir->tmplate) { if (HTStrCaseMatch(dir->tmplate, node->name) == NULL) { make_template(dir, node); } else { HTNewsNode * tmp_node = dir->tmplate_node; /* Should we show this element in the list? */ if (tmp_node->lastChild) { tmp_node->lastChild->show = NO; node->show = NO; } } HTNewsNode_linkRef(dir->tmplate_node, node); } } }