]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Add support for delivering static content from embedded webserver.
authorAndreas Öman <andreas@lonelycoder.com>
Mon, 25 Aug 2008 18:11:28 +0000 (18:11 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Mon, 25 Aug 2008 18:11:28 +0000 (18:11 +0000)
Move extjs app to webui/static/app

webui/extjs.c
webui/static/app/acleditor.js [moved from webui/acleditor.js with 100% similarity]
webui/static/app/cwceditor.js [moved from webui/cwceditor.js with 100% similarity]
webui/static/app/dvb.js [moved from webui/dvb.js with 100% similarity]
webui/static/app/ext.css [moved from webui/ext.css with 100% similarity]
webui/static/app/extensions.js [moved from webui/extensions.js with 100% similarity]
webui/static/app/tvheadend.js [moved from webui/tvheadend.js with 100% similarity]
webui/webui.c

index b14841698dbe47d617c9a4c72c36ab882dfa2a22..b0ab8390d595ddbf8a3a0f489b8094f0e872ea7e 100644 (file)
 
 extern const char *htsversion;
 
-#include "obj/tvheadend.jsh"
-#include "obj/extensions.jsh"
-#include "obj/acleditor.jsh"
-#include "obj/cwceditor.jsh"
-#include "obj/dvb.jsh"
-#include "obj/ext.cssh"
-
-
 static void
 extjs_load(htsbuf_queue_t *hq, const char *script)
 {
@@ -89,7 +81,7 @@ extjs_root(http_connection_t *hc, http_reply_t *hr,
 
   htsbuf_qprintf(hq, "<html><body>\n"
                 "<link rel=\"stylesheet\" type=\"text/css\" href=\""EXTJSPATH"/resources/css/ext-all.css\">\n"
-                "<link rel=\"stylesheet\" type=\"text/css\" href=\"app/extensions.css\">\n"
+                "<link rel=\"stylesheet\" type=\"text/css\" href=\"static/app/ext.css\">\n"
                 "<script type=\"text/javascript\" src=\""EXTJSPATH"/adapter/ext/ext-base.js\"></script>\n"
                 "<script type=\"text/javascript\" src=\""EXTJSPATH"/ext-all-debug.js\"></script>\n");
 
@@ -99,8 +91,7 @@ extjs_root(http_connection_t *hc, http_reply_t *hr,
   /**
    * Load extjs extensions
    */
-  extjs_load(hq, "app/extensions.js");
-  extjs_load(hq, "app/tabclosemenu.js");
+  extjs_load(hq, "static/app/extensions.js");
 
   /**
    * Create a namespace for our app
@@ -110,14 +101,14 @@ extjs_root(http_connection_t *hc, http_reply_t *hr,
   /**
    * Load all components
    */
-  extjs_load(hq, "app/acleditor.js");
-  extjs_load(hq, "app/cwceditor.js");
-  extjs_load(hq, "app/dvb.js");
+  extjs_load(hq, "static/app/acleditor.js");
+  extjs_load(hq, "static/app/cwceditor.js");
+  extjs_load(hq, "static/app/dvb.js");
 
   /**
    * Finally, the app itself
    */
-  extjs_load(hq, "app/tvheadend.js");
+  extjs_load(hq, "static/app/tvheadend.js");
   extjs_exec(hq, "Ext.onReady(tvheadend.app.init, tvheadend.app);");
   
 
@@ -401,16 +392,4 @@ extjs_start(void)
   http_path_add("/dvbtree",     NULL, extjs_dvbtree,     ACCESS_WEB_INTERFACE);
   http_path_add("/dvbadapter",  NULL, extjs_dvbadapter,  ACCESS_WEB_INTERFACE);
   http_path_add("/dvbnetworks", NULL, extjs_dvbnetworks, ACCESS_WEB_INTERFACE);
-
-#define ADD_JS_RESOURCE(path, name) \
-  http_resource_add(path, name, sizeof(name), "text/javascript", "gzip")
-
-  ADD_JS_RESOURCE("/app/extensions.js", embedded_extensions);
-  ADD_JS_RESOURCE("/app/extensions.css", embedded_ext);
-
-  ADD_JS_RESOURCE("/app/tvheadend.js", embedded_tvheadend);
-
-  ADD_JS_RESOURCE("/app/acleditor.js", embedded_acleditor);
-  ADD_JS_RESOURCE("/app/cwceditor.js", embedded_cwceditor);
-  ADD_JS_RESOURCE("/app/dvb.js", embedded_dvb);
 }
similarity index 100%
rename from webui/dvb.js
rename to webui/static/app/dvb.js
similarity index 100%
rename from webui/ext.css
rename to webui/static/app/ext.css
index e6ba79e51d42920c6f87fa18e795543cc2e54339..13ad173cbebff19b12d5cf1d29df5a3f6a9b7a24 100644 (file)
@@ -23,6 +23,9 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <sys/stat.h>
+#include <fcntl.h>
+
 #include "tvhead.h"
 #include "access.h"
 #include "http.h"
@@ -62,6 +65,58 @@ page_root(http_connection_t *hc, http_reply_t *hr,
   return 0;
 }
 
+/**
+ * Root page, we direct the client to different pages depending
+ * on if it is a full blown browser or just some mobile app
+ */
+static int
+page_static(http_connection_t *hc, http_reply_t *hr, 
+           const char *remain, void *opaque)
+{
+  int fd, r;
+  const char *rootpath = HTS_BUILD_ROOT "/tvheadend/webui/static";
+  char path[500];
+  struct stat st;
+  void *buf;
+  htsbuf_queue_t *hq = &hr->hr_q;
+  const char *content = NULL, *postfix;
+
+  if(strstr(remain, ".."))
+    return HTTP_STATUS_BAD_REQUEST;
+
+  snprintf(path, sizeof(path), "%s/%s", rootpath, remain);
+
+  if((fd = open(path, O_RDONLY)) < 0)
+    return 404;
+
+  if(fstat(fd, &st) < 0) {
+    close(fd);
+    return 404;
+  }
+
+  buf = malloc(st.st_size);
+  r = read(fd, buf, st.st_size);
+  close(fd);
+
+  if(r != st.st_size) {
+    free(buf);
+    return 404;
+  }
+
+  postfix = strrchr(remain, '.');
+  if(postfix != NULL) {
+    postfix++;
+
+    if(!strcmp(postfix, "js"))
+      content = "text/javascript; charset=UTF-8";
+  }
+
+  htsbuf_append_prealloc(hq, buf, st.st_size);
+  http_output(hc, hr, content, NULL, 0);
+  return 0;
+}
+
+
 /**
  * WEB user interface
  */
@@ -70,7 +125,10 @@ webui_start(void)
 {
   http_path_add("/", NULL, page_root, ACCESS_WEB_INTERFACE);
 
+  http_path_add("/static", NULL, page_static, ACCESS_WEB_INTERFACE);
+
   simpleui_start();
   extjs_start();
   comet_init();
+
 }