1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#include "commands.h"
#include "music.h"
#include <glib.h>
#include <string.h>
static void commands_list(GSocketConnection *connection, const gchar *cmd) {
gchar **data = g_strsplit(cmd, " ", 2);
for(gint i = 0; data[i]; i++) {
g_debug("\tdata[%d] = %s", i, data[i]);
}
g_assert(data[0] != NULL && data[1] != NULL);
gchar *dirname = g_strdup(data[1]);
struct directory *directory = music_find_dir(dirname);
g_assert(directory != NULL);
GSocket *socket = g_socket_connection_get_socket(connection);
for(struct directory *d = directory->sub; d; d = d->next) {
gchar *name = g_path_get_basename(d->path);
g_socket_send(socket, name, strlen(name), NULL, NULL);
g_socket_send(socket, "\n", 1, NULL, NULL);
g_free(name);
}
for(struct file *f = directory->files; f; f = f->next) {
g_socket_send(socket, f->name, strlen(f->name), NULL, NULL);
g_socket_send(socket, "\n", 1, NULL, NULL);
}
}
void commands_handle(GSocketConnection *connection, const gchar *cmd) {
g_debug("handling command string %s", cmd);
if(g_ascii_strncasecmp(cmd, "/list", 5) == 0) {
commands_list(connection, cmd);
}
}
|