DWORD PreProcessHeaders(PHTTP_FILTER_CONTEXT pFilterContext, PHTTP_FILTER_PREPROC_HEADERS pHeaderInfo) { char url[INTERNET_MAX_URL_LENGTH]; DWORD dwSize= sizeof(url); if (!pHeaderInfo->GetHeader(pFilterContext, "url", url, &dwSize)) { return SF_STATUS_REQ_ERROR; } LogMe(1, "PreProcessHeaders"); if (url[0]!='\0') { boolean rc; char * resultString; char buf[INTERNET_MAX_URL_LENGTH + 32]; sprintf(buf, "Url is: '%s'", url); LogMe(1, buf); // TODO: Load new initialization for each new vdir ? rc= ApplyRules(url, 0, &resultString); if (rc) { sprintf(buf, "Rewrite Url to: '%s'", resultString); LogMe(1, buf); pHeaderInfo->SetHeader(pFilterContext, "url", resultString); free(resultString); // or not? //return SF_STATUS_REQ_HANDLED_NOTIFICATION; // need this?? } else { LogMe(1, "No Rewrite"); } } return SF_STATUS_REQ_NEXT_NOTIFICATION; }
void stem_cz ( BYTE * word ) { ApplyRules ( word, g_dCaseRules, sizeof ( g_dCaseRules ) / sizeof ( g_dCaseRules[0] ) ); ApplyRules ( word, g_dPosessiveRules, sizeof ( g_dPosessiveRules ) / sizeof ( g_dPosessiveRules[0] ) ); }
/* EXPORT */ boolean ApplyRules( char * subject, int depth, /* out */ char **result) { RewriteRule * current= root; boolean retVal= FALSE; char logMsg[512]; int c=0; int rc, i; int *ovector; sprintf(logMsg,"ApplyRules (depth=%d)", depth); LogMe(3, logMsg); // pcre doc says should be a multiple of 3?? why? seems like it ought to be 2. ovector= (int *) malloc((MaxMatchCount*3)*sizeof(int)); if (root==NULL) return retVal; // TODO: employ a MRU cache to map URLs while (current!=NULL) { c++; rc = pcre_exec( current->RE, /* the compiled pattern */ NULL, /* no extra data - we didn't study the pattern */ subject, /* the subject string */ strlen(subject), /* the length of the subject */ 0, /* start at offset 0 in the subject */ 0, /* default options */ ovector, /* output vector for substring information */ MaxMatchCount*3); /* number of elements in the output vector */ if (rc < 0) { if (rc== PCRE_ERROR_NOMATCH) { sprintf(logMsg,"Rule %d : %d", c, rc ); LogMe(3, logMsg); } else { sprintf(logMsg,"Rule %d : %d (unknown error)", c, rc); LogMe(2, logMsg); } } else if (rc == 0) { sprintf(logMsg,"Rule %d : %d (The output vector (%d slots) was not large enough)", c, rc, MaxMatchCount*3); LogMe(2, logMsg); } else { char * newString; sprintf(logMsg,"Rule %d : %d", c, rc); LogMe(2, logMsg); retVal= TRUE; /* generate and Emit the replacement string */ newString= GenerateReplacementString(subject, current->Replacement, ovector, rc); if (sizeof(logMsg)-11> strlen(newString)) { sprintf(logMsg,"Result: %s", newString); LogMe(2,logMsg); } else LogMe(2,"(Log Buffer overflow)"); sprintf(logMsg,"Result length: %d", strlen(newString)); LogMe(3,logMsg); *result= newString; if (depth < IterationLimit) { char * t; boolean rc= ApplyRules(newString, depth+1, &t); if (rc) { *result= t; free(newString); } } else { sprintf(logMsg,"Iteration stopped; reached limit of %d cycles.", IterationLimit); LogMe(2,logMsg); } break; // stop on first match } current= current->next; } return retVal; }