+/**
+ * Lists all experiments for the current user.
+ * @param The context to work in
+ */
+void ListExperiments(FCGIContext *context)
+{
+ DIR * dir = opendir(context->user_dir);
+ if (dir == NULL)
+ {
+ FCGI_RejectJSON(context, "Failed to open user directory");
+ return;
+ }
+ struct dirent * ent;
+ FCGI_BeginJSON(context, STATUS_OK);
+ FCGI_JSONKey("experiments");
+ FCGI_PrintRaw("[");
+
+ bool first = true;
+ while ((ent = readdir(dir)) != NULL) {
+ char *ext = strrchr(ent->d_name, '.');
+ if (ext && !strcmp(ext, ".exp")) {
+ if (!first) {
+ FCGI_PrintRaw(", ");
+ }
+
+ *ext = '\0'; // Ummm... probably not a great idea
+ FCGI_PrintRaw("\"%s\"", ent->d_name);
+ first = false;
+ }
+ }
+ FCGI_PrintRaw("]");
+ FCGI_EndJSON();
+
+ closedir(dir);
+ return;
+}
+