CMake: requires DATADIR, renamed main.c
authorAndrew Karpow <andy@ndyk.de>
Fri, 8 Nov 2013 14:13:10 +0000 (15:13 +0100)
committerAndrew Karpow <andy@ndyk.de>
Fri, 8 Nov 2013 14:13:10 +0000 (15:13 +0100)
src/http_server.c
src/main.c [deleted file]
src/ympd.c [new file with mode: 0644]

index bb6a1d8..8a25271 100644 (file)
@@ -3,8 +3,7 @@
 #include <string.h>
 #include "http_server.h"
 
-#define INSTALL_DATADIR "/home/andy/workspace/ympd"
-#define LOCAL_RESOURCE_PATH INSTALL_DATADIR"/htdocs"
+#define LOCAL_RESOURCE_PATH DATADIR"/htdocs"
 char *resource_path = LOCAL_RESOURCE_PATH;
 
 struct serveable {
@@ -38,7 +37,7 @@ int callback_http(struct libwebsocket_context *context,
        void *in, size_t len)
 {
        char buf[256];
-       int n;
+       size_t n;
 
        switch (reason) {
                case LWS_CALLBACK_HTTP:
diff --git a/src/main.c b/src/main.c
deleted file mode 100644 (file)
index a6b7f52..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-#include <libwebsockets.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/time.h>
-
-#include "http_server.h"
-#include "mpd_client.h"
-
-struct libwebsocket_protocols protocols[] = {
-       /* first protocol must always be HTTP handler */
-       {
-               "http-only",            /* name */
-               callback_http,          /* callback */
-               sizeof (struct per_session_data__http), /* per_session_data_size */
-               0,                      /* max frame size / rx buffer */
-       },
-       {
-               "ympd-client",
-               callback_ympd,
-               sizeof(struct per_session_data__ympd),
-               255,
-       },
-
-       { NULL, NULL, 0, 0 } /* terminator */
-};
-
-int force_exit = 0;
-
-void bye()
-{
-       force_exit = 1;
-}
-
-int main(int argc, char **argv)
-{
-       int n = 0;
-       struct libwebsocket_context *context;
-       int opts = 0;
-       char interface_name[128] = "";
-       const char *iface = NULL;
-       struct lws_context_creation_info info;
-       unsigned int oldus = 0;
-       protocol_array = protocols;
-
-       atexit(bye);
-       memset(&info, 0, sizeof info);
-       info.port = 7681;
-
-       while (n >= 0) {
-               n = getopt(argc, argv, "i:p:");
-               if (n < 0)
-                       continue;
-               switch (n) {
-                       case 'p':
-                       info.port = atoi(optarg);
-                       break;
-                       case 'i':
-                       strncpy(interface_name, optarg, sizeof interface_name);
-                       interface_name[(sizeof interface_name) - 1] = '\0';
-                       iface = interface_name;
-                       break;
-                       case 'h':
-                       fprintf(stderr, "Usage: %s [OPTION]...\n"
-                               "[-=<p>] [--mpd-port=<P>] "
-                               "[-i <log bitfield>] "
-                               "[--resource_path <path>]\n", argv[0]);
-                       exit(1);
-               }
-       }
-
-       info.iface = iface;
-       info.protocols = protocols;
-       info.extensions = libwebsocket_get_internal_extensions();
-       info.gid = -1;
-       info.uid = -1;
-       info.ssl_cert_filepath = NULL;
-       info.ssl_private_key_filepath = NULL;
-       info.options = opts;
-
-       context = libwebsocket_create_context(&info);
-       if (context == NULL) {
-               lwsl_err("libwebsocket init failed\n");
-               return EXIT_FAILURE;
-       }
-
-       n = 0;
-       while (n >= 0 && !force_exit) {
-               struct timeval tv;
-
-               gettimeofday(&tv, NULL);
-
-               /*
-                * This provokes the LWS_CALLBACK_SERVER_WRITEABLE for every
-                * live websocket connection using the DUMB_INCREMENT protocol,
-                * as soon as it can take more packets (usually immediately)
-                */
-
-               if (((unsigned int)tv.tv_usec - oldus) > 1000 * 500) {
-                       mpd_loop();
-                       libwebsocket_callback_on_writable_all_protocol(&protocols[1]);
-                       oldus = tv.tv_usec;
-               }
-
-               n = libwebsocket_service(context, 50);
-       }
-
-       libwebsocket_context_destroy(context);
-       return 0;
-}
diff --git a/src/ympd.c b/src/ympd.c
new file mode 100644 (file)
index 0000000..a6b7f52
--- /dev/null
@@ -0,0 +1,110 @@
+#include <libwebsockets.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/time.h>
+
+#include "http_server.h"
+#include "mpd_client.h"
+
+struct libwebsocket_protocols protocols[] = {
+       /* first protocol must always be HTTP handler */
+       {
+               "http-only",            /* name */
+               callback_http,          /* callback */
+               sizeof (struct per_session_data__http), /* per_session_data_size */
+               0,                      /* max frame size / rx buffer */
+       },
+       {
+               "ympd-client",
+               callback_ympd,
+               sizeof(struct per_session_data__ympd),
+               255,
+       },
+
+       { NULL, NULL, 0, 0 } /* terminator */
+};
+
+int force_exit = 0;
+
+void bye()
+{
+       force_exit = 1;
+}
+
+int main(int argc, char **argv)
+{
+       int n = 0;
+       struct libwebsocket_context *context;
+       int opts = 0;
+       char interface_name[128] = "";
+       const char *iface = NULL;
+       struct lws_context_creation_info info;
+       unsigned int oldus = 0;
+       protocol_array = protocols;
+
+       atexit(bye);
+       memset(&info, 0, sizeof info);
+       info.port = 7681;
+
+       while (n >= 0) {
+               n = getopt(argc, argv, "i:p:");
+               if (n < 0)
+                       continue;
+               switch (n) {
+                       case 'p':
+                       info.port = atoi(optarg);
+                       break;
+                       case 'i':
+                       strncpy(interface_name, optarg, sizeof interface_name);
+                       interface_name[(sizeof interface_name) - 1] = '\0';
+                       iface = interface_name;
+                       break;
+                       case 'h':
+                       fprintf(stderr, "Usage: %s [OPTION]...\n"
+                               "[-=<p>] [--mpd-port=<P>] "
+                               "[-i <log bitfield>] "
+                               "[--resource_path <path>]\n", argv[0]);
+                       exit(1);
+               }
+       }
+
+       info.iface = iface;
+       info.protocols = protocols;
+       info.extensions = libwebsocket_get_internal_extensions();
+       info.gid = -1;
+       info.uid = -1;
+       info.ssl_cert_filepath = NULL;
+       info.ssl_private_key_filepath = NULL;
+       info.options = opts;
+
+       context = libwebsocket_create_context(&info);
+       if (context == NULL) {
+               lwsl_err("libwebsocket init failed\n");
+               return EXIT_FAILURE;
+       }
+
+       n = 0;
+       while (n >= 0 && !force_exit) {
+               struct timeval tv;
+
+               gettimeofday(&tv, NULL);
+
+               /*
+                * This provokes the LWS_CALLBACK_SERVER_WRITEABLE for every
+                * live websocket connection using the DUMB_INCREMENT protocol,
+                * as soon as it can take more packets (usually immediately)
+                */
+
+               if (((unsigned int)tv.tv_usec - oldus) > 1000 * 500) {
+                       mpd_loop();
+                       libwebsocket_callback_on_writable_all_protocol(&protocols[1]);
+                       oldus = tv.tv_usec;
+               }
+
+               n = libwebsocket_service(context, 50);
+       }
+
+       libwebsocket_context_destroy(context);
+       return 0;
+}