Attempting to add ID3 support

This commit is contained in:
Fufu Fang 2019-10-25 18:52:53 +01:00
parent 8a4d47d71d
commit ef53cb83f6
No known key found for this signature in database
GPG Key ID: 0F6BB5EF6F8BB729
4 changed files with 58 additions and 14 deletions

View File

@ -67,7 +67,11 @@ LinkTable *LinkSystem_init(const char *url)
ROOT_LINK_TBL = LinkTable_new(url); ROOT_LINK_TBL = LinkTable_new(url);
} else { } else {
sonic_config_init(url, CONFIG.sonic_username, CONFIG.sonic_password); sonic_config_init(url, CONFIG.sonic_username, CONFIG.sonic_password);
ROOT_LINK_TBL = sonic_LinkTable_new(0); if (!CONFIG.sonic_id3) {
ROOT_LINK_TBL = sonic_LinkTable_new_index_mode(0);
} else {
ROOT_LINK_TBL = sonic_LinkTable_new_id3_mode("/");
}
} }
return ROOT_LINK_TBL; return ROOT_LINK_TBL;
} }
@ -597,11 +601,16 @@ LinkTable *LinkTable_disk_open(const char *dirn)
LinkTable *path_to_Link_LinkTable_new(const char *path) LinkTable *path_to_Link_LinkTable_new(const char *path)
{ {
Link *link = path_to_Link(path); Link *link = path_to_Link(path);
if (!link->next_table) { LinkTable *next_table = link->next_table;
if (next_table) {
if (!CONFIG.sonic_mode) { if (!CONFIG.sonic_mode) {
link->next_table = LinkTable_new(link->f_url); next_table = LinkTable_new(link->f_url);
} else { } else {
link->next_table = sonic_LinkTable_new(link->sonic_id); if (!CONFIG.sonic_id3) {
next_table = sonic_LinkTable_new_index_mode(link->sonic_id);
} else {
next_table = sonic_LinkTable_new_index_mode(link->sonic_id_str);
}
} }
} }
return link->next_table; return link->next_table;
@ -645,13 +654,19 @@ static Link *path_to_Link_recursive(char *path, LinkTable *linktbl)
for (int i = 1; i < linktbl->num; i++) { for (int i = 1; i < linktbl->num; i++) {
if (!strncmp(path, linktbl->links[i]->linkname, MAX_FILENAME_LEN)) { if (!strncmp(path, linktbl->links[i]->linkname, MAX_FILENAME_LEN)) {
/* The next sub-directory exists */ /* The next sub-directory exists */
if (!linktbl->links[i]->next_table) { LinkTable *next_table = linktbl->links[i]->next_table;
if (!next_table) {
if (!CONFIG.sonic_mode) { if (!CONFIG.sonic_mode) {
linktbl->links[i]->next_table = LinkTable_new( next_table = LinkTable_new(
linktbl->links[i]->f_url); linktbl->links[i]->f_url);
} else { } else {
linktbl->links[i]->next_table = sonic_LinkTable_new( if (!CONFIG.sonic_id3) {
linktbl->links[i]->sonic_id); next_table = sonic_LinkTable_new_index_mode(
linktbl->links[i]->sonic_id);
} else {
next_table = sonic_LinkTable_new_id3_mode(
linktbl->links[i]->sonic_id_str);
}
} }
} }
return path_to_Link_recursive( return path_to_Link_recursive(

View File

@ -227,6 +227,7 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc)
break; break;
case 17: case 17:
CONFIG.sonic_id3 = 1; CONFIG.sonic_id3 = 1;
break;
default: default:
fprintf(stderr, "see httpdirfs -h for usage\n"); fprintf(stderr, "see httpdirfs -h for usage\n");
return 1; return 1;

View File

@ -104,7 +104,7 @@ static char *sonic_stream_link(const int id)
} }
/** /**
* \brief Process a single element output by the parser * \brief The parser for Sonic index mode
* \details This is the callback function called by the the XML parser. * \details This is the callback function called by the the XML parser.
* \param[in] data user supplied data, in this case it is the pointer to the * \param[in] data user supplied data, in this case it is the pointer to the
* LinkTable. * LinkTable.
@ -117,7 +117,7 @@ static char *sonic_stream_link(const int id)
* parser terminates the strings properly, which is a fair assumption, * parser terminates the strings properly, which is a fair assumption,
* considering how mature expat is. * considering how mature expat is.
*/ */
static void XMLCALL XML_process_single_element(void *data, const char *elem, static void XMLCALL XML_parser_index_mode(void *data, const char *elem,
const char **attr) const char **attr)
{ {
LinkTable *linktbl = (LinkTable *) data; LinkTable *linktbl = (LinkTable *) data;
@ -231,6 +231,16 @@ static void XMLCALL XML_process_single_element(void *data, const char *elem,
LinkTable_add(linktbl, link); LinkTable_add(linktbl, link);
} }
/**
* \brief The parser for Sonic ID3 mode
* \details Please refer to the details for XML_parser_index_mode()
*/
static void XMLCALL XML_parser_id3_mode(void *data, const char *elem,
const char **attr)
{
LinkTable *linktbl = (LinkTable *) data;
}
/** /**
* \brief parse a XML string in order to fill in the LinkTable * \brief parse a XML string in order to fill in the LinkTable
*/ */
@ -238,7 +248,13 @@ static void sonic_XML_to_LinkTable(DataStruct ds, LinkTable *linktbl)
{ {
XML_Parser parser = XML_ParserCreate(NULL); XML_Parser parser = XML_ParserCreate(NULL);
XML_SetUserData(parser, linktbl); XML_SetUserData(parser, linktbl);
XML_SetStartElementHandler(parser, XML_process_single_element);
if (!CONFIG.sonic_id3) {
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, ds.data, ds.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",
@ -248,7 +264,7 @@ static void sonic_XML_to_LinkTable(DataStruct ds, LinkTable *linktbl)
XML_ParserFree(parser); XML_ParserFree(parser);
} }
LinkTable *sonic_LinkTable_new(const int id) LinkTable *sonic_LinkTable_new_index_mode(const int id)
{ {
char *url; char *url;
if (id > 0) { if (id > 0) {
@ -276,3 +292,9 @@ LinkTable *sonic_LinkTable_new(const int id)
free(url); free(url);
return linktbl; return linktbl;
} }
LinkTable *sonic_LinkTable_new_id3_mode(const char *sonic_id_str)
{
return NULL;
}

View File

@ -14,7 +14,13 @@ void sonic_config_init(const char *server, const char *username,
const char *password); const char *password);
/** /**
* \brief Create a new Sonic LinkTable * \brief Create a new Sonic LinkTable in index mode)
*/ */
LinkTable *sonic_LinkTable_new(const int id); LinkTable *sonic_LinkTable_new_index_mode(const int id);
/**
* \brief Create a new Sonic LinkTable in ID3 mode)
*/
LinkTable *sonic_LinkTable_new_id3_mode(const char *sonic_id_str);
#endif #endif