json_t *app_list = NULL;
char *apps_directory = NULL;
+char *content_directory = NULL;
+
json_t *event_queue = NULL;
char *voicecallmanager_path = NULL;
libwebsockets_serve_http_file(wsi, path,
(const char *)efreet_mime_type_get((char *)path));
} else {
- snprintf(filename, 256, "%s/%s", LOCAL_RESOURCE_PATH, (char *)in + 1);
- if (strlen((char *)in) == 1)
- /* serve up default content */
- libwebsockets_serve_http_file(wsi, DEFAULTCONTENT, "text/html");
- else if (!stat(filename, &info) && S_ISREG(info.st_mode))
+ snprintf(filename, 256, "%s/%s", content_directory, (char *)in + 1);
+ if (!stat(filename, &info) && S_ISDIR(info.st_mode))
+ /* try serving up index.html */
+ snprintf(filename, 256, "%s/%s/index.html",
+ content_directory, (char *)in + 1);
+
+ if (!stat(filename, &info) && S_ISREG(info.st_mode)) {
libwebsockets_serve_http_file(wsi, filename,
- (const char *)efreet_mime_type_get((char *)in));
- else
- fprintf(stderr, "Failed to find content: %s\n", (char *)in);
+ (const char *)efreet_mime_type_get(filename));
+ printf("serving: %s\n", filename);
+ } else {
+ /* TODO: Serve up error html page */
+ fprintf(stderr, "Unable to find %s\n", filename);
+ }
}
} else {
fprintf(stderr, "Invalid request \'%s\'\n", (char *)in);
}
static struct option options[] = {
- { "help", no_argument, NULL, 'h' },
- { "port", required_argument, NULL, 'p' },
- { "directory", required_argument, NULL, 'd' },
+ { "help", no_argument, NULL, 'h' },
+ { "port", required_argument, NULL, 'p' },
+ { "appsdir", required_argument, NULL, 'a' },
+ { "contentdir", required_argument, NULL, 'c' },
{ NULL, 0, 0, 0 }
};
if (n < 0)
continue;
switch (n) {
- case 'd':
+ case 'a':
apps_directory = strdup(optarg);
break;
+ case 'c':
+ content_directory = strdup(optarg);
+ break;
case 'p':
port = atoi(optarg);
break;
case 'h':
- fprintf(stderr, "Usage: %s [--port=<p>] [--directory=<d>]\n", argv[0]);
+ default:
+ fprintf(stderr, "Usage: %s [--port=<p>] [--appsdir=<a>] [--contentdir=<c>]\n", argv[0]);
exit(-1);
}
}
if (!apps_directory)
apps_directory = APPDIR;
-
+ if (!content_directory)
+ content_directory = LOCAL_RESOURCE_PATH;
+
/* Initialize and build up the application list */
app_list = json_array();
build_app_list(apps_directory);