+ const char *suffix;
+ suffix = strrchr(url, '.');
+ if ((suffix != NULL) && (strcmp(suffix, ".tcl") == 0))
+ {
+ printf("Run tcl %s\n", url);
+
+ int retcode;
+
+ const char *script = alloc_printf(
+ "global httpdata; source {%s}; set httpdata", url);
+ retcode = Jim_Eval_Named(interp, script, "httpd.c", __LINE__);
+ free((void *) script);
+
+ if (retcode == JIM_ERR)
+ {
+ printf("Tcl failed\n");
+ const char *t = httpd_exec_cgi_tcl_error(interp);
+ if (t == NULL)
+ return MHD_NO;
+
+ response = MHD_create_response_from_data(strlen(t), (void *) t,
+ MHD_YES, MHD_NO);
+ ret = MHD_queue_response(connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR, response);
+ MHD_destroy_response(response);
+ return ret;
+ }
+ else
+ {
+ LOG_DEBUG("Tcl OK");
+ /* FIX!!! how to handle mime types??? */
+ const char *result;
+ int reslen;
+ result = Jim_GetString(Jim_GetResult(interp), &reslen);
+
+ response = MHD_create_response_from_data(reslen, (void *) result,
+ MHD_NO, MHD_YES);
+ ret = MHD_queue_response(connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR, response);
+ MHD_destroy_response(response);
+ return ret;
+ }
+ }
+ else
+ {
+ void *data;
+ size_t len;
+
+ int retval = loadFile(url, &data, &len);
+ if (retval != ERROR_OK)
+ {
+ printf("Did not find %s\n", url);
+
+ response = MHD_create_response_from_data(strlen(PAGE_NOT_FOUND),
+ (void *) PAGE_NOT_FOUND, MHD_NO, MHD_NO);
+ ret = MHD_queue_response(connection, MHD_HTTP_NOT_FOUND, response);
+ MHD_destroy_response(response);
+ return ret;
+ }
+
+ LOG_DEBUG("Serving %s length=%zu", url, len);
+ /* serve file directly */
+ response = MHD_create_response_from_data(len, data, MHD_YES, MHD_NO);
+ MHD_add_response_header(response, "Content-Type", "image/png");