+ // we don't screw with "All" category that mmenu.c generates on the fly
+ if ( strncmp ( catname, "All ", 4 ) == 0 ) {
+ goto category_done_audit;
+ }
+
+ // check if category came from an ovr-file; if so, we implicitly trust it instead of enforcing rules
+ if ( app -> object_flags & ( PND_DISCO_CUSTOM1 | PND_DISCO_CUSTOM2 ) ) {
+ goto category_done_audit;
+ }
+
+ // category cleansing; lets..
+ // - ensure we only let good freedesktop categories through
+ // - we fix case.. no more UtIliTy (a good cat, studlycaps)
+ // - no more good cats but swapped ancestry; Utility as child of something?
+ // - if bogus, we just ship it off to BAD_CAT
+
+ unsigned char cat_is_clean = 1;
+ freedesktop_cat_t *fdcat = NULL, *fdpcat = NULL;
+ fdcat = freedesktop_category_query ( catname, parentcatname );
+ if ( parentcatname ) {
+ fdpcat = freedesktop_category_query ( parentcatname, NULL );
+ }
+
+ // ensure requested cat is good
+ if ( ! fdcat ) {
+ // requested cat is bad, send it to Other
+ cat_is_clean = 0;
+ printf ( "PXML Fail %s: Cat request %s (parent %s) -> bad cat\n", app -> title_en ? app -> title_en : "no name?", catname, parentcatname ? parentcatname : "n/a" );
+
+ // do the Other substitution right away, so remaining code has something to look at in fdcat
+ fdcat = freedesktop_category_query ( BADCATNAME, NULL );
+ catname = fdcat -> cat;
+ fdpcat = NULL;
+ parentcatname = NULL;
+
+ } else {
+ // use canonicle entry, so our Case is now correct!
+ catname = fdcat -> cat;
+ }
+
+ // ensure parent is good, if specified
+ if ( parentcatname ) {
+ if ( ! fdpcat ) {
+ // requested cat is bad, send it to Other
+ cat_is_clean = 0;
+ printf ( "PXML Fail %s: Cat request %s (parent %s) -> parent bad cat\n", app -> title_en ? app -> title_en : "no name?", catname, parentcatname ? parentcatname : "n/a" );
+ // fix immediately so code doesn't explode
+ parentcatname = NULL;
+ } else {
+ // use canonicle entry, so our Case is now correct!
+ parentcatname = fdpcat -> cat;
+ }
+ }
+
+ // ensure ancestry is good
+ // - if cat request is for child, ensure its a child
+ // - if parent specified, ensure its a parent
+ // - if child specified, ensure its parent is the right parent(?!)
+ //
+ if ( parentcatname ) {
+ // implies catname request is for child, with parent parentcatname
+
+ if ( fdcat -> parent_cat == NULL ) {
+ // but wait, catname is actually a parent cat...
+ cat_is_clean = 0;
+ printf ( "PXML Fail %s: Cat request %s (parent %s) -> cat wants to be child, but FD says its a parent\n", app -> title_en ? app -> title_en : "no name?", catname, parentcatname ? parentcatname : "n/a" );
+ }
+ if ( fdpcat -> parent_cat ) {
+ // but wait, parent cat is actually a subcat!
+ cat_is_clean = 0;
+ printf ( "PXML Fail %s: Cat request %s (parent %s) -> parent cat, FD says its a child\n", app -> title_en ? app -> title_en : "no name?", catname, parentcatname ? parentcatname : "n/a" );
+ }
+
+ } else {
+ // implies request is for a parent cat - itself has no parent
+
+ if ( fdcat -> parent_cat ) {
+ // but wait, cat actually has a parent!
+ cat_is_clean = 0;
+ printf ( "PXML Fail %s: Cat request %s (parent %s) -> cat wants to be parent, FD says its a child\n", app -> title_en ? app -> title_en : "no name?", catname, parentcatname ? parentcatname : "n/a" );
+ }
+
+ }
+
+ // ensure that if this is a child cat, its parent is the right parent
+ if ( parentcatname ) {
+ if ( ( ! fdcat -> parent_cat ) ||
+ ( ! fdpcat ) )
+ {
+ // child cat points to a different parent than requested parent!
+ cat_is_clean = 0;
+ printf ( "PXML Fail %s: Cat request %s (parent %s) -> cat wants to be child of a cat which FD says is the wrong parent (1)\n", app -> title_en ? app -> title_en : "no name?", catname, parentcatname ? parentcatname : "n/a" );
+ } else if ( strcasecmp ( fdcat -> parent_cat, fdpcat -> cat ) != 0 ) {
+ // child cat points to a different parent than requested parent!
+ cat_is_clean = 0;
+ printf ( "PXML Fail %s: Cat request %s (parent %s) -> cat wants to be child of a cat which FD says is the wrong parent (2)\n", app -> title_en ? app -> title_en : "no name?", catname, parentcatname ? parentcatname : "n/a" );
+ }
+ }
+
+ // did testing fail? if so, bump to Other!
+ //
+ if ( ! cat_is_clean ) {
+ // set Other visibility
+ visiblep = cat_is_visible ( g_conf, BADCATNAME );
+ // fix cat request
+ fdcat = freedesktop_category_query ( BADCATNAME, NULL );
+ catname = fdcat -> cat;
+ // nullify parent cat request (if any)
+ fdpcat = NULL;
+ parentcatname = NULL;
+ } else {
+ //printf ( "PXML Category Pass: Cat request %s (parent %s)\n", catname, parentcatname ? parentcatname : "n/a" );
+ }