PRIVATE BOOL HTRank (HTRequest * request, HTArray * variants) { HTContentDescription * cd; void ** data; if (!variants) { HTTRACE(PROT_TRACE, "Ranking..... No variants\n"); return NO; } /* ** Walk through the list of local and global preferences and find the ** overall q factor for each variant */ cd = (HTContentDescription *) HTArray_firstObject(variants, data); while (cd) { double ctq_local = type_value(cd->content_type, HTRequest_conversion(request)); double ctq_global = type_value(cd->content_type, HTFormat_conversion()); double clq_local = lang_value(cd->content_language, HTRequest_language(request)); double clq_global = lang_value(cd->content_language, HTFormat_language()); double ceq_local = encoding_value(cd->content_encoding, HTRequest_encoding(request)); double ceq_global = encoding_value(cd->content_encoding, HTFormat_contentCoding()); HTTRACE(PROT_TRACE, "Qualities... Content type: %.3f, Content language: %.3f, Content encoding: %.3f\n" _ HTMAX(ctq_local, ctq_global) _ HTMAX(clq_local, clq_global) _ HTMAX(ceq_local, ceq_global)); cd->quality *= (HTMAX(ctq_local, ctq_global) * HTMAX(clq_local, clq_global) * HTMAX(ceq_local, ceq_global)); cd = (HTContentDescription *) HTArray_nextObject(variants, data); } /* Sort the array of all our accepted preferences */ HTArray_sort(variants, VariantSort); /* Write out the result */ #ifdef HTDEBUG if (PROT_TRACE) { int cnt = 1; cd = (HTContentDescription *) HTArray_firstObject(variants, data); HTTRACE(PROT_TRACE, "Ranking.....\n"); HTTRACE(PROT_TRACE, "RANK QUALITY CONTENT-TYPE LANGUAGE ENCODING FILE\n"); while (cd) { HTTRACE(PROT_TRACE, "%d. %.4f %-20.20s %-8.8s %-10.10s %s\n" _ cnt++ _ cd->quality _ cd->content_type ? HTAtom_name(cd->content_type) : "-" _ cd->content_language?HTAtom_name(cd->content_language):"-" _ cd->content_encoding?HTAtom_name(cd->content_encoding):"-" _ cd->filename ? cd->filename :"-"); cd = (HTContentDescription *) HTArray_nextObject(variants, data); } } #endif /* HTDEBUG */ return YES; }
/* HTDir_free ** ---------- ** If we are sorting then do the sorting and put out the list, ** else just append the end of the list. */ PUBLIC BOOL HTDir_free (HTDir * dir) { if (!dir) return NO; if (dir->key != HT_DK_NONE) { HTArray *array = dir->array; void **data = NULL; HTDirNode *node; HTDir_headLine(dir); HTArray_sort(array, (dir->key==HT_DK_CINS ? DirCaseSort : DirSort)); node = (HTDirNode *) HTArray_firstObject(array, data); while (node) { HTDirNode_print(dir, node); HTDirNode_free(node); node = (HTDirNode *) HTArray_nextObject(array, data); } dir->size = HTArray_size(array); HTArray_delete(array); } /* Put out the end of the HTML stuff */ { HTStructured *target = dir->target; END(HTML_PRE); START(HTML_HR); START(HTML_PRE); if (!dir->size) PUTS("Empty directory"); else if (dir->size == 1) PUTS("1 File"); else { char buffer[20]; sprintf(buffer, "%u files", dir->size); PUTS(buffer); } END(HTML_PRE); END(HTML_BODY); END(HTML_HTML); FREE_TARGET; } HT_FREE(dir->fnbuf); HT_FREE(dir->lnbuf); HT_FREE(dir->base); HT_FREE(dir); return YES; }
/* HTNewsDir_free ** -------------- ** If we are sorting then do the sorting and put out the list, ** else just append the end of the list. */ PUBLIC BOOL HTNewsDir_free (HTNewsDir * dir) { if (!dir) return NO; if (dir->key != HT_NDK_NONE) { HTArray * array = dir->array; HTArray * cache = NULL; HTComparer * comp = NULL; /* ** Find a suitable sort key for this listing. The sort function ** depends on the type of new listing we have received. */ if (dir->key == HT_NDK_INDEX) /* Sort by Message Number */ comp = NDirIndexSort; else if (dir->key == HT_NDK_DATE) /* Sort by Date */ comp = NDirDateSort; else if (dir->key == HT_NDK_SUBJECT) /* Sort after Subject */ comp = NDirSubjectSort; else if (dir->key == HT_NDK_FROM) /* Sort after From */ comp = NDirFromSort; else if (dir->key == HT_NDK_GROUP) { /* Sort as group hierarchi */ comp = NDirGroupSort; } else if (dir->key == HT_NDK_REFTHREAD) { /* Added by MP. */ HTNewsDir_setRefInfo (dir); comp = NDirRefThreadSort; } else { HTTRACE(STREAM_TRACE, "NewsListing. Invalid sortkey\n"); return NO; } /* ** Now sort the array of news items that we have read with the sort ** function defined by the sort key above. */ HTArray_sort(array, comp); /* ** If we are showing a group listing then run through the list and ** identify group hierarchy. We have to sort the thing again in order ** to get the new template groups included */ if (dir->key == HT_NDK_GROUP) { HTNewsDir_setGroupInfo(dir); HTArray_sort(array, comp); } /* ** After we have sorted the listing, we can write out the result and ** free the array. */ { void ** data; HTNewsNode *node = (HTNewsNode *) HTArray_firstObject(array, data); while (node) { HTNewsNode_print(dir, node); /* ** Create a special array for the cache containing the group ** names only and no templates */ if (dir->key == HT_NDK_GROUP && !node->is_tmplate) HTArray_addObject(cache, node->name); HTNewsNode_delete(node, (dir->cache!=NULL)); node = (HTNewsNode *) HTArray_nextObject(array, data); } HTArray_delete(array); } /* Update the cache */ if (dir->cache) HTNewsCache_after(dir->request, NULL, dir->cache, 0); } /* Put out the end of the HTML stuff */ { HTStructured *target = dir->target; /* END(HTML_UL); */ HTNewsDir_addLevelTags (dir, -1); START(HTML_HR); END(HTML_BODY); END(HTML_HTML); FREE_TARGET; } /* Clean up the dir object */ HT_FREE(dir->name); HT_FREE(dir->tmplate); HT_FREE(dir); return YES; }