mirror of
https://github.com/SuperBFG7/ympd
synced 2024-11-26 23:07:17 +00:00
removes old Makefile, reindent, fixups
This commit is contained in:
parent
25f77b71ce
commit
062810144c
@ -12,6 +12,7 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
|
|||||||
FIND_PACKAGE(LibWebSockets REQUIRED)
|
FIND_PACKAGE(LibWebSockets REQUIRED)
|
||||||
FIND_PACKAGE(LibMPDClient REQUIRED)
|
FIND_PACKAGE(LibMPDClient REQUIRED)
|
||||||
INCLUDE(CheckCSourceCompiles)
|
INCLUDE(CheckCSourceCompiles)
|
||||||
|
INCLUDE(CPack)
|
||||||
|
|
||||||
SET(SOURCES
|
SET(SOURCES
|
||||||
src/ympd.c
|
src/ympd.c
|
||||||
@ -20,7 +21,7 @@ SET(SOURCES
|
|||||||
)
|
)
|
||||||
|
|
||||||
ADD_EXECUTABLE(ympd ${SOURCES})
|
ADD_EXECUTABLE(ympd ${SOURCES})
|
||||||
ADD_DEFINITIONS(-DDATADIR="${CMAKE_INSTALL_PREFIX}/share")
|
ADD_DEFINITIONS(-DDATADIR="${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(ympd ${LIBMPDCLIENT_LIBRARY} ${LIBWEBSOCKETS_LIBRARIES})
|
TARGET_LINK_LIBRARIES(ympd ${LIBMPDCLIENT_LIBRARY} ${LIBWEBSOCKETS_LIBRARIES})
|
||||||
|
|
||||||
|
13
src/Makefile
13
src/Makefile
@ -1,13 +0,0 @@
|
|||||||
CFLAGS = -Wall -Os
|
|
||||||
LFLAGS = `pkg-config --libs libwebsockets libmpdclient`
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
|
|
||||||
ympd: main.o http_server.o mpd_client.o
|
|
||||||
$(CC) $(LFLAGS) $^ -o $@
|
|
||||||
|
|
||||||
%.o: %.c
|
|
||||||
$(CC) -c $(CFLAGS) $< -o $@
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f main.o http_server.o mpd_client.o ympd
|
|
@ -8,3 +8,4 @@ int callback_http(struct libwebsocket_context *context,
|
|||||||
struct libwebsocket *wsi,
|
struct libwebsocket *wsi,
|
||||||
enum libwebsocket_callback_reasons reason, void *user,
|
enum libwebsocket_callback_reasons reason, void *user,
|
||||||
void *in, size_t len);
|
void *in, size_t len);
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include "mpd_client.h"
|
#include "mpd_client.h"
|
||||||
|
|
||||||
#define MAX_SIZE 9000*10
|
#define MAX_SIZE 1024 * 100
|
||||||
|
|
||||||
struct mpd_connection *conn = NULL;
|
struct mpd_connection *conn = NULL;
|
||||||
enum mpd_conn_states mpd_conn_state = MPD_DISCONNECTED;
|
enum mpd_conn_states mpd_conn_state = MPD_DISCONNECTED;
|
||||||
@ -62,16 +62,12 @@ int callback_ympd(struct libwebsocket_context *context,
|
|||||||
pss->do_send &= ~DO_SEND_BROWSE;
|
pss->do_send &= ~DO_SEND_BROWSE;
|
||||||
free(pss->browse_path);
|
free(pss->browse_path);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
n = mpd_put_state(p);
|
n = mpd_put_state(p);
|
||||||
}
|
|
||||||
|
|
||||||
if(n > 0)
|
if(n > 0)
|
||||||
m = libwebsocket_write(wsi, (unsigned char *)p, n, LWS_WRITE_TEXT);
|
m = libwebsocket_write(wsi, (unsigned char *)p, n, LWS_WRITE_TEXT);
|
||||||
|
|
||||||
if(p != NULL)
|
|
||||||
printf("Sending out: %s\n", p);
|
|
||||||
|
|
||||||
if (m < n) {
|
if (m < n) {
|
||||||
lwsl_err("ERROR %d writing to socket\n", n, m);
|
lwsl_err("ERROR %d writing to socket\n", n, m);
|
||||||
free(buf);
|
free(buf);
|
||||||
@ -81,8 +77,6 @@ int callback_ympd(struct libwebsocket_context *context,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LWS_CALLBACK_RECEIVE:
|
case LWS_CALLBACK_RECEIVE:
|
||||||
printf("Got %s\n", (char *)in);
|
|
||||||
|
|
||||||
if(!strcmp((const char *)in, MPD_API_GET_PLAYLIST))
|
if(!strcmp((const char *)in, MPD_API_GET_PLAYLIST))
|
||||||
pss->do_send |= DO_SEND_PLAYLIST;
|
pss->do_send |= DO_SEND_PLAYLIST;
|
||||||
else if(!strcmp((const char *)in, MPD_API_GET_TRACK_INFO))
|
else if(!strcmp((const char *)in, MPD_API_GET_TRACK_INFO))
|
||||||
@ -144,7 +138,6 @@ int callback_ympd(struct libwebsocket_context *context,
|
|||||||
else if(!strncmp((const char *)in, MPD_API_GET_BROWSE, sizeof(MPD_API_GET_BROWSE)-1)) {
|
else if(!strncmp((const char *)in, MPD_API_GET_BROWSE, sizeof(MPD_API_GET_BROWSE)-1)) {
|
||||||
char *dir;
|
char *dir;
|
||||||
if(sscanf(in, "MPD_API_GET_BROWSE,%m[^\t\n]", &dir) && dir != NULL) {
|
if(sscanf(in, "MPD_API_GET_BROWSE,%m[^\t\n]", &dir) && dir != NULL) {
|
||||||
printf("sending '%s'\n", dir);
|
|
||||||
pss->do_send |= DO_SEND_BROWSE;
|
pss->do_send |= DO_SEND_BROWSE;
|
||||||
pss->browse_path = dir;
|
pss->browse_path = dir;
|
||||||
}
|
}
|
||||||
@ -152,12 +145,10 @@ int callback_ympd(struct libwebsocket_context *context,
|
|||||||
else if(!strncmp((const char *)in, MPD_API_ADD_TRACK, sizeof(MPD_API_ADD_TRACK)-1)) {
|
else if(!strncmp((const char *)in, MPD_API_ADD_TRACK, sizeof(MPD_API_ADD_TRACK)-1)) {
|
||||||
char *uri;
|
char *uri;
|
||||||
if(sscanf(in, "MPD_API_ADD_TRACK,%m[^\t\n]", &uri) && uri != NULL) {
|
if(sscanf(in, "MPD_API_ADD_TRACK,%m[^\t\n]", &uri) && uri != NULL) {
|
||||||
printf("sending '%s'\n", uri);
|
|
||||||
mpd_run_add(conn, uri);
|
mpd_run_add(conn, uri);
|
||||||
free(uri);
|
free(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -5,21 +5,6 @@
|
|||||||
#define DO_SEND_TRACK_INFO (1 << 2)
|
#define DO_SEND_TRACK_INFO (1 << 2)
|
||||||
#define DO_SEND_BROWSE (1 << 3)
|
#define DO_SEND_BROWSE (1 << 3)
|
||||||
|
|
||||||
|
|
||||||
struct libwebsocket_protocols *protocol_array;
|
|
||||||
|
|
||||||
struct per_session_data__ympd {
|
|
||||||
int do_send;
|
|
||||||
unsigned queue_version;
|
|
||||||
char *browse_path;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum mpd_conn_states {
|
|
||||||
MPD_FAILURE,
|
|
||||||
MPD_DISCONNECTED,
|
|
||||||
MPD_CONNECTED
|
|
||||||
};
|
|
||||||
|
|
||||||
#define MPD_API_GET_SEEK "MPD_API_GET_SEEK"
|
#define MPD_API_GET_SEEK "MPD_API_GET_SEEK"
|
||||||
#define MPD_API_GET_PLAYLIST "MPD_API_GET_PLAYLIST"
|
#define MPD_API_GET_PLAYLIST "MPD_API_GET_PLAYLIST"
|
||||||
#define MPD_API_GET_TRACK_INFO "MPD_API_GET_TRACK_INFO"
|
#define MPD_API_GET_TRACK_INFO "MPD_API_GET_TRACK_INFO"
|
||||||
@ -41,13 +26,22 @@ enum mpd_conn_states {
|
|||||||
#define MPD_API_TOGGLE_SINGLE "MPD_API_TOGGLE_SINGLE"
|
#define MPD_API_TOGGLE_SINGLE "MPD_API_TOGGLE_SINGLE"
|
||||||
#define MPD_API_TOGGLE_REPEAT "MPD_API_TOGGLE_REPEAT"
|
#define MPD_API_TOGGLE_REPEAT "MPD_API_TOGGLE_REPEAT"
|
||||||
|
|
||||||
|
struct per_session_data__ympd {
|
||||||
|
int do_send;
|
||||||
|
unsigned queue_version;
|
||||||
|
char *browse_path;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum mpd_conn_states {
|
||||||
|
MPD_FAILURE,
|
||||||
|
MPD_DISCONNECTED,
|
||||||
|
MPD_CONNECTED
|
||||||
|
};
|
||||||
|
|
||||||
int callback_ympd(struct libwebsocket_context *context,
|
int callback_ympd(struct libwebsocket_context *context,
|
||||||
struct libwebsocket *wsi,
|
struct libwebsocket *wsi,
|
||||||
enum libwebsocket_callback_reasons reason,
|
enum libwebsocket_callback_reasons reason,
|
||||||
void *user, void *in, size_t len);
|
void *user, void *in, size_t len);
|
||||||
|
|
||||||
void mpd_loop();
|
void mpd_loop();
|
||||||
int mpd_put_state(char *buffer);
|
int mpd_put_state(char *buffer);
|
||||||
int mpd_put_current_song(char *buffer);
|
int mpd_put_current_song(char *buffer);
|
||||||
|
80
src/ympd.c
80
src/ympd.c
@ -2,11 +2,15 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include "http_server.h"
|
#include "http_server.h"
|
||||||
#include "mpd_client.h"
|
#include "mpd_client.h"
|
||||||
|
|
||||||
|
extern char *optarg;
|
||||||
|
extern char *resource_path;
|
||||||
|
|
||||||
struct libwebsocket_protocols protocols[] = {
|
struct libwebsocket_protocols protocols[] = {
|
||||||
/* first protocol must always be HTTP handler */
|
/* first protocol must always be HTTP handler */
|
||||||
{
|
{
|
||||||
@ -14,15 +18,17 @@ struct libwebsocket_protocols protocols[] = {
|
|||||||
callback_http, /* callback */
|
callback_http, /* callback */
|
||||||
sizeof (struct per_session_data__http), /* per_session_data_size */
|
sizeof (struct per_session_data__http), /* per_session_data_size */
|
||||||
0, /* max frame size / rx buffer */
|
0, /* max frame size / rx buffer */
|
||||||
|
0, /* no_buffer_all_partial_tx */
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ympd-client",
|
"ympd-client",
|
||||||
callback_ympd,
|
callback_ympd,
|
||||||
sizeof(struct per_session_data__ympd),
|
sizeof(struct per_session_data__ympd),
|
||||||
255,
|
255,
|
||||||
|
0,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ NULL, NULL, 0, 0 } /* terminator */
|
{ NULL, NULL, 0, 0, 0 } /* terminator */
|
||||||
};
|
};
|
||||||
|
|
||||||
int force_exit = 0;
|
int force_exit = 0;
|
||||||
@ -34,49 +40,75 @@ void bye()
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n, gid = -1, uid = -1;
|
||||||
struct libwebsocket_context *context;
|
struct libwebsocket_context *context;
|
||||||
int opts = 0;
|
const char *cert_filepath = NULL;
|
||||||
char interface_name[128] = "";
|
const char *private_key_filepath = NULL;
|
||||||
const char *iface = NULL;
|
const char *iface = NULL;
|
||||||
struct lws_context_creation_info info;
|
struct lws_context_creation_info info;
|
||||||
unsigned int oldus = 0;
|
unsigned int oldus = 0;
|
||||||
protocol_array = protocols;
|
|
||||||
|
|
||||||
atexit(bye);
|
atexit(bye);
|
||||||
memset(&info, 0, sizeof info);
|
memset(&info, 0, sizeof info);
|
||||||
info.port = 7681;
|
info.port = 80;
|
||||||
|
|
||||||
while (n >= 0) {
|
while((n = getopt(argc, argv, "i:p:r:c:k:g:u:h")) != -1) {
|
||||||
n = getopt(argc, argv, "i:p:");
|
|
||||||
if (n < 0)
|
|
||||||
continue;
|
|
||||||
switch (n) {
|
switch (n) {
|
||||||
|
case 'i':
|
||||||
|
iface = optarg;
|
||||||
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
info.port = atoi(optarg);
|
info.port = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'r':
|
||||||
strncpy(interface_name, optarg, sizeof interface_name);
|
resource_path = optarg;
|
||||||
interface_name[(sizeof interface_name) - 1] = '\0';
|
|
||||||
iface = interface_name;
|
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
cert_filepath = optarg;
|
||||||
|
break;
|
||||||
|
case 'k':
|
||||||
|
private_key_filepath = optarg;
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
gid = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
uid = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
case 'h':
|
case 'h':
|
||||||
fprintf(stderr, "Usage: %s [OPTION]...\n"
|
lwsl_err("Usage: %s [OPTION]...\n"
|
||||||
"[-=<p>] [--mpd-port=<P>] "
|
"\t[-p <port>]\n"
|
||||||
"[-i <log bitfield>] "
|
"\t[-i <interface>]\n"
|
||||||
"[--resource_path <path>]\n", argv[0]);
|
"\t[-r <htdocs path>]\n"
|
||||||
exit(1);
|
"\t[-c <ssl certificate filepath>]\n"
|
||||||
|
"\t[-k <ssl private key filepath>]\n"
|
||||||
|
"\t[-g <group id after socket bind>]\n"
|
||||||
|
"\t[-u <user id after socket bind>]\n"
|
||||||
|
"\t[-h]\n"
|
||||||
|
, argv[0]);
|
||||||
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(cert_filepath != NULL && private_key_filepath == NULL) {
|
||||||
|
lwsl_err("private key filepath needed\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(private_key_filepath != NULL && cert_filepath == NULL) {
|
||||||
|
lwsl_err("public cert filepath needed\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
info.ssl_cert_filepath = cert_filepath;
|
||||||
|
info.ssl_private_key_filepath = private_key_filepath;
|
||||||
info.iface = iface;
|
info.iface = iface;
|
||||||
info.protocols = protocols;
|
info.protocols = protocols;
|
||||||
info.extensions = libwebsocket_get_internal_extensions();
|
info.extensions = libwebsocket_get_internal_extensions();
|
||||||
info.gid = -1;
|
info.gid = gid;
|
||||||
info.uid = -1;
|
info.uid = uid;
|
||||||
info.ssl_cert_filepath = NULL;
|
info.options = 0;
|
||||||
info.ssl_private_key_filepath = NULL;
|
|
||||||
info.options = opts;
|
|
||||||
|
|
||||||
context = libwebsocket_create_context(&info);
|
context = libwebsocket_create_context(&info);
|
||||||
if (context == NULL) {
|
if (context == NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user