From: Rusty Lynch Date: Mon, 20 Aug 2012 19:51:02 +0000 (-0700) Subject: Add support for a new --contentdir command line argument which allows X-Git-Tag: accepted/trunk/20120910.213415~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=52f92a8542c61458279367f3689e84521f78583d;p=profile%2Fivi%2Fsockdrawer.git Add support for a new --contentdir command line argument which allows the binary to be run from a different directory then where the HTML content is compiled to be located --- diff --git a/main.c b/main.c index eed39b6..2a0685b 100644 --- a/main.c +++ b/main.c @@ -36,6 +36,8 @@ E_DBus_Connection *bus; json_t *app_list = NULL; char *apps_directory = NULL; +char *content_directory = NULL; + json_t *event_queue = NULL; char *voicecallmanager_path = NULL; @@ -132,15 +134,20 @@ callback_http(struct libwebsocket_context *context, 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); @@ -704,9 +711,10 @@ get_modems_reply(void *data, DBusMessage *reply, DBusError *error) } 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 } }; @@ -730,20 +738,26 @@ int main(int argc, char **argv) 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=

] [--directory=]\n", argv[0]); + default: + fprintf(stderr, "Usage: %s [--port=

] [--appsdir=] [--contentdir=]\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);