not sure why it crashes
This commit is contained in:
parent
ef53cb83f6
commit
83f88dbe38
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
||||||
VERSION=1.2.0
|
VERSION=1.2.0
|
||||||
|
|
||||||
CFLAGS += -O2 -Wall -Wextra -Wshadow -rdynamic -D_GNU_SOURCE\
|
CFLAGS += -g -O2 -Wall -Wextra -Wshadow -rdynamic -D_GNU_SOURCE\
|
||||||
-D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\"\
|
-D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\"\
|
||||||
`pkg-config --cflags-only-I gumbo libcurl fuse uuid expat`
|
`pkg-config --cflags-only-I gumbo libcurl fuse uuid expat`
|
||||||
LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto -luuid -lexpat
|
LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto -luuid -lexpat
|
||||||
|
|
|
@ -609,7 +609,7 @@ LinkTable *path_to_Link_LinkTable_new(const char *path)
|
||||||
if (!CONFIG.sonic_id3) {
|
if (!CONFIG.sonic_id3) {
|
||||||
next_table = sonic_LinkTable_new_index_mode(link->sonic_id);
|
next_table = sonic_LinkTable_new_index_mode(link->sonic_id);
|
||||||
} else {
|
} else {
|
||||||
next_table = sonic_LinkTable_new_index_mode(link->sonic_id_str);
|
next_table = sonic_LinkTable_new_id3_mode(link->sonic_id_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -629,6 +629,7 @@ static Link *path_to_Link_recursive(char *path, LinkTable *linktbl)
|
||||||
*slash = '\0';
|
*slash = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
puts(path);
|
||||||
slash = strchr(path, '/');
|
slash = strchr(path, '/');
|
||||||
if ( slash == NULL ) {
|
if ( slash == NULL ) {
|
||||||
/* We cannot find another '/', we have reached the last level */
|
/* We cannot find another '/', we have reached the last level */
|
||||||
|
|
82
src/sonic.c
82
src/sonic.c
|
@ -244,24 +244,38 @@ static void XMLCALL XML_parser_id3_mode(void *data, const char *elem,
|
||||||
/**
|
/**
|
||||||
* \brief parse a XML string in order to fill in the LinkTable
|
* \brief parse a XML string in order to fill in the LinkTable
|
||||||
*/
|
*/
|
||||||
static void sonic_XML_to_LinkTable(DataStruct ds, LinkTable *linktbl)
|
static LinkTable *sonic_url_to_LinkTable(const char *url,
|
||||||
|
XML_StartElementHandler handler)
|
||||||
{
|
{
|
||||||
|
LinkTable *linktbl = LinkTable_alloc(url);
|
||||||
|
|
||||||
|
/* start downloading the base URL */
|
||||||
|
DataStruct xml = Link_to_DataStruct(linktbl->links[0]);
|
||||||
|
if (xml.size == 0) {
|
||||||
|
LinkTable_free(linktbl);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
XML_Parser parser = XML_ParserCreate(NULL);
|
XML_Parser parser = XML_ParserCreate(NULL);
|
||||||
XML_SetUserData(parser, linktbl);
|
XML_SetUserData(parser, linktbl);
|
||||||
|
|
||||||
if (!CONFIG.sonic_id3) {
|
XML_SetStartElementHandler(parser, handler);
|
||||||
XML_SetStartElementHandler(parser, XML_parser_index_mode);
|
|
||||||
} else {
|
|
||||||
XML_SetStartElementHandler(parser, XML_parser_id3_mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (XML_Parse(parser, ds.data, ds.size, 1) == XML_STATUS_ERROR) {
|
if (XML_Parse(parser, xml.data, xml.size, 1) == XML_STATUS_ERROR) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"sonic_XML_to_LinkTable(): Parse error at line %lu: %s\n",
|
"sonic_XML_to_LinkTable(): Parse error at line %lu: %s\n",
|
||||||
XML_GetCurrentLineNumber(parser),
|
XML_GetCurrentLineNumber(parser),
|
||||||
XML_ErrorString(XML_GetErrorCode(parser)));
|
XML_ErrorString(XML_GetErrorCode(parser)));
|
||||||
}
|
}
|
||||||
|
|
||||||
XML_ParserFree(parser);
|
XML_ParserFree(parser);
|
||||||
|
|
||||||
|
free(xml.data);
|
||||||
|
|
||||||
|
LinkTable_print(linktbl);
|
||||||
|
|
||||||
|
return linktbl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkTable *sonic_LinkTable_new_index_mode(const int id)
|
LinkTable *sonic_LinkTable_new_index_mode(const int id)
|
||||||
|
@ -272,29 +286,47 @@ LinkTable *sonic_LinkTable_new_index_mode(const int id)
|
||||||
} else {
|
} else {
|
||||||
url = sonic_gen_url_first_part("getIndexes");
|
url = sonic_gen_url_first_part("getIndexes");
|
||||||
}
|
}
|
||||||
|
LinkTable *linktbl = sonic_url_to_LinkTable(url, XML_parser_index_mode);
|
||||||
printf("%s\n", url);
|
|
||||||
|
|
||||||
LinkTable *linktbl = LinkTable_alloc(url);
|
|
||||||
|
|
||||||
/* start downloading the base URL */
|
|
||||||
DataStruct xml = Link_to_DataStruct(linktbl->links[0]);
|
|
||||||
if (xml.size == 0) {
|
|
||||||
LinkTable_free(linktbl);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
sonic_XML_to_LinkTable(xml, linktbl);
|
|
||||||
|
|
||||||
LinkTable_print(linktbl);
|
|
||||||
|
|
||||||
free(xml.data);
|
|
||||||
free(url);
|
free(url);
|
||||||
return linktbl;
|
return linktbl;
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkTable *sonic_LinkTable_new_id3_mode(const char *sonic_id_str)
|
LinkTable *sonic_LinkTable_new_id3_root()
|
||||||
{
|
{
|
||||||
|
char *url = sonic_gen_url_first_part("getArtists");
|
||||||
|
LinkTable *linktbl = sonic_url_to_LinkTable(url, XML_parser_index_mode);
|
||||||
|
free(url);
|
||||||
|
return linktbl;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinkTable *sonic_LinkTable_new_id3_mode(char *sonic_id_str)
|
||||||
|
{
|
||||||
|
/* Count the number of '/' */
|
||||||
|
int n = 0;
|
||||||
|
for (char *c = sonic_id_str; *c; c++) {
|
||||||
|
if (*c == '/') {
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *url;
|
||||||
|
switch (n) {
|
||||||
|
/* Root level */
|
||||||
|
case 1:
|
||||||
|
break;
|
||||||
|
/* Index level */
|
||||||
|
case 2:
|
||||||
|
break;
|
||||||
|
/* Artist level */
|
||||||
|
case 3:
|
||||||
|
break;
|
||||||
|
/* Album level*/
|
||||||
|
case 4:
|
||||||
|
break;
|
||||||
|
/* Invalid */
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/sonic.h
12
src/sonic.h
|
@ -14,13 +14,19 @@ void sonic_config_init(const char *server, const char *username,
|
||||||
const char *password);
|
const char *password);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Create a new Sonic LinkTable in index mode)
|
* \brief Create a new Sonic LinkTable in index mode
|
||||||
*/
|
*/
|
||||||
LinkTable *sonic_LinkTable_new_index_mode(const int id);
|
LinkTable *sonic_LinkTable_new_index_mode(const int id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Create a new Sonic LinkTable in ID3 mode)
|
* \brief Create a new Sonic LinkTable in ID3 mode
|
||||||
|
* \details In this mode, the filesystem effectively has 4 levels of
|
||||||
|
* directories, which are:
|
||||||
|
* 1. Root
|
||||||
|
* 2. Index
|
||||||
|
* 3. Artists
|
||||||
|
* 4. Album
|
||||||
*/
|
*/
|
||||||
LinkTable *sonic_LinkTable_new_id3_mode(const char *sonic_id_str);
|
LinkTable *sonic_LinkTable_new_id3_mode(char *sonic_id_str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue