+int client_parse_sort(struct client *cl, struct reclist_sortparms *sp)
+{
+ if (sp)
+ {
+ const char *sort_strategy_and_spec =
+ get_strategy_plus_sort(cl, sp->name);
+ int increasing = sp->increasing;
+ if (sort_strategy_and_spec && strlen(sort_strategy_and_spec) < 40)
+ {
+ char strategy[50], *p;
+ strcpy(strategy, sort_strategy_and_spec);
+ p = strchr(strategy, ':');
+ if (p)
+ {
+ // Split the string in two
+ *p++ = 0;
+ while (*p == ' ')
+ p++;
+ if (increasing)
+ strcat(p, " <");
+ else
+ strcat(p, " >");
+ yaz_log(YLOG_LOG, "Client %s: applying sorting %s %s", client_get_id(cl), strategy, p);
+ if (!cl->sort_strategy || strcmp(cl->sort_strategy, strategy))
+ cl->same_search = 0;
+ if (!cl->sort_criteria || strcmp(cl->sort_criteria, p))
+ cl->same_search = 0;
+ if (cl->same_search == 0) {
+ xfree(cl->sort_strategy);
+ cl->sort_strategy = xstrdup(strategy);
+ xfree(cl->sort_criteria);
+ cl->sort_criteria = xstrdup(p);
+ }
+ }
+ else {
+ yaz_log(YLOG_LOG, "Client %s: Invalid sort strategy and spec found %s", client_get_id(cl), sort_strategy_and_spec);
+ xfree(cl->sort_strategy);
+ cl->sort_strategy = 0;
+ xfree(cl->sort_criteria);
+ cl->sort_criteria = 0;
+ }
+ } else {
+ yaz_log(YLOG_DEBUG, "Client %s: No sort strategy and spec found.", client_get_id(cl));
+ xfree(cl->sort_strategy);
+ cl->sort_strategy = 0;
+ xfree(cl->sort_criteria);
+ cl->sort_criteria = 0;
+ }
+
+ }
+ return !cl->same_search;
+}
+