Hi, the function "sort_criteria_comparision" contains plenty of bugs:
After upgrading my Noxon2 to the latest firmware it sends browsing requests with sort-information but now the gmediaserver boosts up to 100% CPU. Having a quick look at sort_criteria_comparision there are 3 bugs within this few lines of code: - sorting by more than one criteria does never work - the while loop may never be left (that was here the case - 100% CPU) - the function uses pointer comparision for sorting if everything else fails? I've attached my current patch that does not really fix all the problems but works for me. Attached is a browsing request: <u:Browse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1"> <ObjectID>0</ObjectID> <BrowseFlag>BrowseDirectChildren</BrowseFlag> <Filter>@childCount,dc:creator,upnp:album,upnp:artist,res,[EMAIL PROTECTED],[EMAIL PROTECTED],upnp:searchClass</Filter> <StartingIndex>0</StartingIndex> <RequestedCount>50</RequestedCount> <SortCriteria>+dc:title</SortCriteria> </u:Browse> I didn't check why p1 and p2 are null, my quick guess is, that the plus sign is not expected and so the attribute not found. Cheers Leif
--- src/contentdir.c.orig 2006-08-31 22:30:09.000000000 +0200 +++ src/contentdir.c 2007-03-25 18:10:10.000000000 +0200 @@ -145,8 +145,15 @@ const Entry *e1 = k1; const Entry *e2 = k2; + if ( criteria->first == NULL ) { + /* default sorting */ + return strcasecmp(e1->name, e2->name); + } + sort_entry = criteria->first; - while (sort_entry != NULL) { + + /* FIXME: sorting by multiple criterias will never work */ + while (sort_entry != NULL) { /* FIXME: sort_entry is never updated! */ char *p1 = get_entry_property(e1, sort_entry->property); char *p2 = get_entry_property(e2, sort_entry->property); @@ -154,11 +161,11 @@ free(p2); return (sort_entry->ascending ? -1 : 1); } - if (p1 != NULL && p2 == NULL) { + else if (p1 != NULL && p2 == NULL) { free(p1); return (sort_entry->ascending ? 1 : -1); } - if (p1 != NULL && p2 != NULL) { + else if (p1 != NULL && p2 != NULL) { int compare; compare = strcmp(p1, p2); @@ -167,9 +174,12 @@ if (compare != 0) return (sort_entry->ascending ? compare : -compare); } + else { /* both are null - bail out!!! */ + return strcasecmp(e1->name, e2->name); + } } - return e1-e2; + return e1-e2; /* FIXME: sorting by pointer compare? */ } void