mirror of
				https://github.com/SuperBFG7/ympd
				synced 2025-10-31 05:43:01 +00:00 
			
		
		
		
	removes old Makefile, reindent, fixups
This commit is contained in:
		| @@ -12,6 +12,7 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/") | ||||
| FIND_PACKAGE(LibWebSockets REQUIRED) | ||||
| FIND_PACKAGE(LibMPDClient REQUIRED) | ||||
| INCLUDE(CheckCSourceCompiles) | ||||
| INCLUDE(CPack) | ||||
|  | ||||
| SET(SOURCES | ||||
|     src/ympd.c | ||||
| @@ -20,7 +21,7 @@ SET(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}) | ||||
|  | ||||
|   | ||||
							
								
								
									
										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, | ||||
|         enum libwebsocket_callback_reasons reason, void *user, | ||||
|         void *in, size_t len); | ||||
|  | ||||
|   | ||||
| @@ -14,7 +14,7 @@ | ||||
|  | ||||
| #include "mpd_client.h" | ||||
|  | ||||
| #define MAX_SIZE 9000*10 | ||||
| #define MAX_SIZE 1024 * 100 | ||||
|  | ||||
| struct mpd_connection *conn = NULL; | ||||
| 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; | ||||
|                 free(pss->browse_path); | ||||
|             } | ||||
| 			else { | ||||
|             else | ||||
|                 n = mpd_put_state(p); | ||||
| 			} | ||||
|  | ||||
|             if(n > 0) | ||||
|                 m = libwebsocket_write(wsi, (unsigned char *)p, n, LWS_WRITE_TEXT); | ||||
|  | ||||
| 			if(p != NULL) | ||||
| 				printf("Sending out: %s\n", p); | ||||
|  | ||||
|             if (m < n) { | ||||
|                 lwsl_err("ERROR %d writing to socket\n", n, m); | ||||
|                 free(buf); | ||||
| @@ -81,8 +77,6 @@ int callback_ympd(struct libwebsocket_context *context, | ||||
|             break; | ||||
|  | ||||
|         case LWS_CALLBACK_RECEIVE: | ||||
| 			printf("Got %s\n", (char *)in); | ||||
|  | ||||
|             if(!strcmp((const char *)in, MPD_API_GET_PLAYLIST)) | ||||
|                 pss->do_send |= DO_SEND_PLAYLIST; | ||||
|             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)) { | ||||
|                 char *dir; | ||||
|                 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->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)) { | ||||
|                 char *uri; | ||||
|                 if(sscanf(in, "MPD_API_ADD_TRACK,%m[^\t\n]", &uri) && uri != NULL) { | ||||
| 					printf("sending '%s'\n", uri); | ||||
|                     mpd_run_add(conn, uri); | ||||
|                     free(uri); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             break; | ||||
|  | ||||
|         default: | ||||
|   | ||||
| @@ -5,21 +5,6 @@ | ||||
| #define DO_SEND_TRACK_INFO (1 << 2) | ||||
| #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_PLAYLIST     "MPD_API_GET_PLAYLIST" | ||||
| #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_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, | ||||
|         struct libwebsocket *wsi, | ||||
|         enum libwebsocket_callback_reasons reason, | ||||
|         void *user, void *in, size_t len); | ||||
|  | ||||
| void mpd_loop(); | ||||
| int mpd_put_state(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 <string.h> | ||||
| #include <stdio.h> | ||||
| #include <unistd.h> | ||||
| #include <sys/time.h> | ||||
|  | ||||
| #include "http_server.h" | ||||
| #include "mpd_client.h" | ||||
|  | ||||
| extern char *optarg; | ||||
| extern char *resource_path; | ||||
|  | ||||
| struct libwebsocket_protocols protocols[] = { | ||||
|     /* first protocol must always be HTTP handler */ | ||||
|     { | ||||
| @@ -14,15 +18,17 @@ struct libwebsocket_protocols protocols[] = { | ||||
|         callback_http,		/* callback */ | ||||
|         sizeof (struct per_session_data__http),	/* per_session_data_size */ | ||||
|         0,			/* max frame size / rx buffer */ | ||||
|         0,          /* no_buffer_all_partial_tx */ | ||||
|     }, | ||||
|     { | ||||
|         "ympd-client", | ||||
|         callback_ympd, | ||||
|         sizeof(struct per_session_data__ympd), | ||||
|         255, | ||||
|         0, | ||||
|     }, | ||||
|  | ||||
| 	{ NULL, NULL, 0, 0 } /* terminator */ | ||||
|     { NULL, NULL, 0, 0, 0 } /* terminator */ | ||||
| }; | ||||
|  | ||||
| int force_exit = 0; | ||||
| @@ -34,49 +40,75 @@ void bye() | ||||
|  | ||||
| int main(int argc, char **argv) | ||||
| { | ||||
| 	int n = 0; | ||||
|     int n, gid = -1, uid = -1; | ||||
|     struct libwebsocket_context *context; | ||||
| 	int opts = 0; | ||||
| 	char interface_name[128] = ""; | ||||
|     const char *cert_filepath = NULL; | ||||
|     const char *private_key_filepath = NULL; | ||||
|     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; | ||||
|     info.port = 80; | ||||
|  | ||||
| 	while (n >= 0) { | ||||
| 		n = getopt(argc, argv, "i:p:"); | ||||
| 		if (n < 0) | ||||
| 			continue; | ||||
|     while((n = getopt(argc, argv, "i:p:r:c:k:g:u:h")) != -1) { | ||||
|         switch (n) { | ||||
|             case 'i': | ||||
|                 iface = optarg; | ||||
|                 break; | ||||
|             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; | ||||
|             case 'r': | ||||
|                 resource_path = optarg; | ||||
|                 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': | ||||
| 			fprintf(stderr, "Usage: %s [OPTION]...\n" | ||||
| 				"[-=<p>] [--mpd-port=<P>] " | ||||
| 				"[-i <log bitfield>] " | ||||
| 				"[--resource_path <path>]\n", argv[0]); | ||||
| 			exit(1); | ||||
|                 lwsl_err("Usage: %s [OPTION]...\n" | ||||
|                         "\t[-p <port>]\n" | ||||
|                         "\t[-i <interface>]\n" | ||||
|                         "\t[-r <htdocs path>]\n" | ||||
|                         "\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.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; | ||||
|     info.gid = gid; | ||||
|     info.uid = uid; | ||||
|     info.options = 0; | ||||
|  | ||||
|     context = libwebsocket_create_context(&info); | ||||
|     if (context == NULL) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Andrew Karpow
					Andrew Karpow