/* ** 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; }
PUBLIC int HTMIMEParseSet_delete (HTMIMEParseSet * me, const char * token) { int hash, i; HTMIMEParseEl * pEl, ** last; hash = HTMIMEParseSet_hash(me, token); pEl = me->parsers[hash]; last = &me->parsers[hash]; for (i = 0; i < 2; i++) { /* do both */ for (; pEl; last = &pEl->next, pEl = pEl->next) { if ((pEl->caseSensitive && !strcmp(pEl->token, token)) || (!pEl->caseSensitive && !strcasecomp(pEl->token, token))) { return HTMIMEParseEl_delete(pEl, last); } } pEl = me->regexParsers; last = &me->regexParsers; } return HT_ERROR; }
PUBLIC HTMIMEParseEl * HTMIMEParseSet_add (HTMIMEParseSet * me, const char * token, BOOL caseSensitive, HTParserCallback * callback) { int hash; /* Insure hash list */ if (!me->parsers) { if (!me->size) me->size = HT_S_HASH_SIZE; if ((me->parsers = (HTMIMEParseEl **) HT_CALLOC(me->size, sizeof(HTMIMEParseEl *))) == NULL) HT_OUTOFMEM("HTMIME parsers"); } hash = HTMIMEParseSet_hash(me, token); /* Add a new entry */ return HTMIMEParseEl_new(&me->parsers[hash], token, caseSensitive, callback); }