/* * Returns a description string (that must not be HT_FREEd!) * for a file with name name in directory dirname. * Description file contents is in descriptions list. */ PUBLIC char * HTGetDescription (HTList * descriptions, char * dirname, char * filename, HTFormat format) { HTList * cur = descriptions; char * t; if (!dirname || !filename) return NULL; /* * descriptions may well be NULL in which case we may still * want to peek the titles. */ while ((t = (char*)HTList_nextObject(cur))) { char * d = strchr(t,' '); if (!d) continue; *d = 0; #if 0 if (HTAA_templateMatch(t,filename)) { #else if (HTStrMatch(t, filename)) { #endif *d = ' '; return d+1; } *d = ' '; } if (HTPeekTitles && format == WWW_HTML) return HTPeekTitle(dirname, filename); else return NULL; }
/* ** Returns the icon corresponding to content_type or content_encoding. ** If no match is found then use "unknown icon" */ PUBLIC HTIconNode * HTIcon_find (HTFileMode mode, HTFormat content_type, HTEncoding content_encoding) { if (!icon_unknown) icon_unknown = icon_blank; if (mode == HT_IS_FILE) { const char * ct = content_type ? HTAtom_name(content_type) : NULL; const char * ce = content_encoding ? HTAtom_name(content_encoding) : NULL; HTList * cur = icons; HTIconNode * node; while ((node = (HTIconNode*)HTList_nextObject(cur))) { char * slash = strchr(node->type_templ,'/'); if ((ct && slash && match(node->type_templ,ct)) || (ce && !slash && HTStrMatch(node->type_templ,ce))) { return node; } } } else if (mode == HT_IS_DIR) { return icon_dir ? icon_dir : icon_unknown; } else if (mode == HT_IS_BLANK) { return icon_blank ? icon_blank : icon_unknown; } else if (mode == HT_IS_PARENT) { return icon_parent ? icon_parent : icon_unknown; } return icon_unknown; }
PRIVATE BOOL match (char * templ, const char * actual) { static char * c1 = NULL; static char * c2 = NULL; char * slash1; char * slash2; StrAllocCopy(c1,templ); StrAllocCopy(c2,actual); slash1 = strchr(c1,'/'); slash2 = strchr(c2,'/'); if (slash1 && slash2) { *slash1++ = 0; *slash2++ = 0; return HTStrMatch(c1,c2) && HTStrMatch(slash1,slash2); } else if (!slash1 && !slash2) return HTStrMatch(c1,c2) ? YES : NO; else return NO; }
/* 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; }