succesfully mounted the filesystem, now need to actually download the music file
This commit is contained in:
parent
5062f511bd
commit
0f7623d1e7
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@ CFLAGS+= -O2 -Wall -Wextra -Wshadow\
|
|||
-D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\"\
|
||||
`pkg-config --cflags-only-I gumbo libcurl fuse uuid expat`
|
||||
LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto -luuid -lexpat
|
||||
COBJS = network.o fuse_local.o link.o cache.o util.o main.o
|
||||
COBJS = main.o network.o fuse_local.o link.o cache.o util.o sonic.o
|
||||
|
||||
prefix ?= /usr/local
|
||||
|
||||
|
|
37
src/link.c
37
src/link.c
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "cache.h"
|
||||
#include "network.h"
|
||||
#include "sonic.h"
|
||||
|
||||
#include <gumbo.h>
|
||||
|
||||
|
@ -49,16 +50,25 @@ LinkTable *LinkSystem_init(const char *url)
|
|||
}
|
||||
|
||||
/* ----------- Enable cache system --------------------*/
|
||||
if (CONFIG.cache_enabled) {
|
||||
if (CONFIG.cache_dir) {
|
||||
CacheSystem_init(CONFIG.cache_dir, 0);
|
||||
} else {
|
||||
CacheSystem_init(url, 1);
|
||||
/* For now, disable cache mode if sonic mode is enabled */
|
||||
if (!CONFIG.sonic_mode) {
|
||||
if (CONFIG.cache_enabled) {
|
||||
if (CONFIG.cache_dir) {
|
||||
CacheSystem_init(CONFIG.cache_dir, 0);
|
||||
} else {
|
||||
CacheSystem_init(url, 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sonic_config_init(url, CONFIG.sonic_username, CONFIG.sonic_password);
|
||||
}
|
||||
|
||||
/* ----------- Create the root link table --------------*/
|
||||
ROOT_LINK_TBL = LinkTable_new(url);
|
||||
if (!CONFIG.sonic_mode) {
|
||||
ROOT_LINK_TBL = LinkTable_new(url);
|
||||
} else {
|
||||
ROOT_LINK_TBL = sonic_LinkTable_new(0);
|
||||
}
|
||||
return ROOT_LINK_TBL;
|
||||
}
|
||||
|
||||
|
@ -578,7 +588,11 @@ LinkTable *path_to_Link_LinkTable_new(const char *path)
|
|||
{
|
||||
Link *link = path_to_Link(path);
|
||||
if (!link->next_table) {
|
||||
link->next_table = LinkTable_new(link->f_url);
|
||||
if (!CONFIG.sonic_mode) {
|
||||
link->next_table = LinkTable_new(link->f_url);
|
||||
} else {
|
||||
link->next_table = sonic_LinkTable_new(link->sonic_id);
|
||||
}
|
||||
}
|
||||
return link->next_table;
|
||||
}
|
||||
|
@ -622,8 +636,13 @@ static Link *path_to_Link_recursive(char *path, LinkTable *linktbl)
|
|||
if (!strncmp(path, linktbl->links[i]->linkname, MAX_FILENAME_LEN)) {
|
||||
/* The next sub-directory exists */
|
||||
if (!linktbl->links[i]->next_table) {
|
||||
linktbl->links[i]->next_table = LinkTable_new(
|
||||
linktbl->links[i]->f_url);
|
||||
if (!CONFIG.sonic_mode) {
|
||||
linktbl->links[i]->next_table = LinkTable_new(
|
||||
linktbl->links[i]->f_url);
|
||||
} else {
|
||||
linktbl->links[i]->next_table = sonic_LinkTable_new(
|
||||
linktbl->links[i]->sonic_id);
|
||||
}
|
||||
}
|
||||
return path_to_Link_recursive(
|
||||
next_path, linktbl->links[i]->next_table);
|
||||
|
|
|
@ -69,7 +69,7 @@ struct Link {
|
|||
/** \brief The pointer associated with the cache file */
|
||||
Cache *cache_ptr;
|
||||
/**
|
||||
* \brief Subsonic Music Directory ID
|
||||
* \brief Sonic Music Directory ID
|
||||
* \details We use linkname to store filename
|
||||
*/
|
||||
int sonic_id;
|
||||
|
|
46
src/sonic.c
46
src/sonic.c
|
@ -22,7 +22,7 @@ typedef struct {
|
|||
static SonicConfigStruct SONIC_CONFIG;
|
||||
|
||||
/**
|
||||
* \brief initalise Subsonic configuration struct
|
||||
* \brief initalise Sonic configuration struct
|
||||
*/
|
||||
void sonic_config_init(const char *server, const char *username,
|
||||
const char *password)
|
||||
|
@ -33,8 +33,8 @@ void sonic_config_init(const char *server, const char *username,
|
|||
if (SONIC_CONFIG.server[server_url_len] == '/') {
|
||||
SONIC_CONFIG.server[server_url_len] = '\0';
|
||||
}
|
||||
SONIC_CONFIG.http_username = strndup(username, MAX_FILENAME_LEN);
|
||||
SONIC_CONFIG.http_password = strndup(password, MAX_FILENAME_LEN);
|
||||
SONIC_CONFIG.username = strndup(username, MAX_FILENAME_LEN);
|
||||
SONIC_CONFIG.password = strndup(password, MAX_FILENAME_LEN);
|
||||
SONIC_CONFIG.client = DEFAULT_USER_AGENT;
|
||||
/*
|
||||
* API 1.13.0 is the minimum version that supports
|
||||
|
@ -49,16 +49,16 @@ void sonic_config_init(const char *server, const char *username,
|
|||
static char *sonic_gen_auth_str()
|
||||
{
|
||||
char *salt = generate_salt();
|
||||
size_t password_len = strnlen(SONIC_CONFIG.http_password, MAX_FILENAME_LEN);
|
||||
size_t password_len = strnlen(SONIC_CONFIG.password, MAX_FILENAME_LEN);
|
||||
size_t password_salt_len = password_len + strnlen(salt, MAX_FILENAME_LEN);
|
||||
char *password_salt = CALLOC(password_salt_len + 1, sizeof(char));
|
||||
strncat(password_salt, SONIC_CONFIG.http_password, MAX_FILENAME_LEN);
|
||||
strncat(password_salt, SONIC_CONFIG.password, MAX_FILENAME_LEN);
|
||||
strncat(password_salt + password_len, salt, MAX_FILENAME_LEN);
|
||||
char *token = generate_md5sum(password_salt);
|
||||
char *auth_str = CALLOC(MAX_PATH_LEN + 1, sizeof(char));
|
||||
snprintf(auth_str, MAX_PATH_LEN,
|
||||
".view?u=%s&t=%s&s=%s&v=%s&c=%s",
|
||||
SONIC_CONFIG.http_username, token, salt,
|
||||
SONIC_CONFIG.username, token, salt,
|
||||
SONIC_CONFIG.api_version, SONIC_CONFIG.client);
|
||||
free(salt);
|
||||
free(token);
|
||||
|
@ -144,10 +144,19 @@ static void XMLCALL XML_process_single_element(void *data, const char *elem,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp("name", attr[i]) || !strcmp("title", attr[i])) {
|
||||
strncpy(link->linkname, attr[i+1], MAX_FILENAME_LEN);
|
||||
linkname_set = 1;
|
||||
continue;
|
||||
if (!linkname_set) {
|
||||
if (!strcmp("name", attr[i])) {
|
||||
strncpy(link->linkname, attr[i+1], MAX_FILENAME_LEN);
|
||||
linkname_set = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp("path", attr[i])) {
|
||||
strncpy(link->linkname, strrchr(attr[i+1], '/') + 1,
|
||||
MAX_FILENAME_LEN);
|
||||
linkname_set = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp("isDir", attr[i])) {
|
||||
|
@ -225,7 +234,6 @@ static void sonic_XML_to_LinkTable(DataStruct ds, LinkTable *linktbl)
|
|||
XML_ParserFree(parser);
|
||||
}
|
||||
|
||||
|
||||
LinkTable *sonic_LinkTable_new(const int id)
|
||||
{
|
||||
char *url;
|
||||
|
@ -252,19 +260,5 @@ LinkTable *sonic_LinkTable_new(const int id)
|
|||
|
||||
free(xml.data);
|
||||
free(url);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
sonic_config_init(argv[1], argv[2], argv[3]);
|
||||
|
||||
Config_init();
|
||||
NetworkSystem_init();
|
||||
|
||||
sonic_LinkTable_new(0);
|
||||
sonic_LinkTable_new(3);
|
||||
return linktbl;
|
||||
}
|
||||
|
|
|
@ -2,14 +2,19 @@
|
|||
#define SONIC_H
|
||||
/**
|
||||
* \file sonic.h
|
||||
* \brief Subsonic related function
|
||||
* \brief Sonic related function
|
||||
*/
|
||||
|
||||
#include "link.h"
|
||||
|
||||
/**
|
||||
* \brief Initialise SubSonic configuration.
|
||||
* \brief Initialise Sonic configuration.
|
||||
*/
|
||||
void sonic_config_init(const char *server, const char *username,
|
||||
const char *password);
|
||||
|
||||
/**
|
||||
* \brief Create a new Sonic LinkTable
|
||||
*/
|
||||
LinkTable *sonic_LinkTable_new(const int id);
|
||||
#endif
|
||||
|
|
|
@ -81,7 +81,7 @@ void Config_init(void)
|
|||
|
||||
CONFIG.max_segbc = DEFAULT_MAX_SEGBC;
|
||||
|
||||
/*-------------- Subsonic related -------------*/
|
||||
/*-------------- Sonic related -------------*/
|
||||
CONFIG.sonic_mode = 0;
|
||||
|
||||
CONFIG.sonic_username = NULL;
|
||||
|
|
|
@ -63,11 +63,11 @@ typedef struct {
|
|||
/** \brief The maximum segment count for a single cache file */
|
||||
int max_segbc;
|
||||
|
||||
/** \brief Whether we are using the Subsonic mode */
|
||||
/** \brief Whether we are using the Sonic mode */
|
||||
int sonic_mode;
|
||||
/** \brief The Subsonic server username */
|
||||
/** \brief The Sonic server username */
|
||||
char *sonic_username;
|
||||
/** \brief The Subsonic server password */
|
||||
/** \brief The Sonic server password */
|
||||
char *sonic_password;
|
||||
} ConfigStruct;
|
||||
|
||||
|
|
Loading…
Reference in New Issue