moved the *sonic related fields into a separate struct
This commit is contained in:
parent
e7f06285df
commit
31f8509f42
10
src/cache.c
10
src/cache.c
|
@ -1,5 +1,7 @@
|
|||
#include "cache.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
@ -575,7 +577,7 @@ void Cache_delete(const char *fn)
|
|||
{
|
||||
if (CONFIG.mode == SONIC) {
|
||||
Link *link = path_to_Link(fn);
|
||||
fn = link->sonic_id;
|
||||
fn = link->sonic.id;
|
||||
}
|
||||
|
||||
char *metafn = path_append(META_DIR, fn);
|
||||
|
@ -673,7 +675,7 @@ int Cache_create(const char *path)
|
|||
} else if (CONFIG.mode == SINGLE) {
|
||||
fn = curl_easy_unescape(NULL, this_link->linkname, 0, NULL);
|
||||
} else if (CONFIG.mode == SONIC) {
|
||||
fn = this_link->sonic_id;
|
||||
fn = this_link->sonic.id;
|
||||
} else {
|
||||
lprintf(fatal, "Invalid CONFIG.mode\n");
|
||||
}
|
||||
|
@ -755,7 +757,7 @@ Cache *Cache_open(const char *fn)
|
|||
return NULL;
|
||||
}
|
||||
} else if (CONFIG.mode == SONIC) {
|
||||
if (Cache_exist(link->sonic_id)) {
|
||||
if (Cache_exist(link->sonic.id)) {
|
||||
|
||||
lprintf(cache_lock_debug,
|
||||
"thread %x: unlocking cf_lock;\n", pthread_self());
|
||||
|
@ -781,7 +783,7 @@ Cache *Cache_open(const char *fn)
|
|||
* Set the path for the local cache file, if we are in sonic mode
|
||||
*/
|
||||
if (CONFIG.mode == SONIC) {
|
||||
fn = link->sonic_id;
|
||||
fn = link->sonic.id;
|
||||
}
|
||||
|
||||
cf->path = strndup(fn, MAX_PATH_LEN);
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
* separate folders.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <pthread.h>
|
||||
|
||||
/**
|
||||
|
|
13
src/link.c
13
src/link.c
|
@ -1,5 +1,6 @@
|
|||
#include "link.h"
|
||||
|
||||
#include "util.h"
|
||||
#include "cache.h"
|
||||
#include "network.h"
|
||||
#include "sonic.h"
|
||||
|
@ -677,11 +678,11 @@ LinkTable *path_to_Link_LinkTable_new(const char *path)
|
|||
next_table = LinkTable_new(link->f_url);
|
||||
} else if (CONFIG.mode == SONIC) {
|
||||
if (!CONFIG.sonic_id3) {
|
||||
next_table = sonic_LinkTable_new_index(link->sonic_id);
|
||||
next_table = sonic_LinkTable_new_index(link->sonic.id);
|
||||
} else {
|
||||
next_table =
|
||||
sonic_LinkTable_new_id3(link->sonic_depth,
|
||||
link->sonic_id);
|
||||
sonic_LinkTable_new_id3(link->sonic.depth,
|
||||
link->sonic.id);
|
||||
}
|
||||
} else {
|
||||
lprintf(fatal, "Invalid CONFIG.mode\n");
|
||||
|
@ -752,13 +753,13 @@ static Link *path_to_Link_recursive(char *path, LinkTable * linktbl)
|
|||
if (!CONFIG.sonic_id3) {
|
||||
next_table =
|
||||
sonic_LinkTable_new_index
|
||||
(linktbl->links[i]->sonic_id);
|
||||
(linktbl->links[i]->sonic.id);
|
||||
} else {
|
||||
next_table =
|
||||
sonic_LinkTable_new_id3
|
||||
(linktbl->links
|
||||
[i]->sonic_depth,
|
||||
linktbl->links[i]->sonic_id);
|
||||
[i]->sonic.depth,
|
||||
linktbl->links[i]->sonic.id);
|
||||
}
|
||||
} else {
|
||||
lprintf(fatal, "Invalid CONFIG.mode\n");
|
||||
|
|
80
src/link.h
80
src/link.h
|
@ -5,16 +5,18 @@
|
|||
* \file link.h
|
||||
* \brief link related structures and functions
|
||||
*/
|
||||
|
||||
typedef struct Link Link;
|
||||
typedef struct LinkTable LinkTable;
|
||||
|
||||
#include "sonic.h"
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
#include "cache.h"
|
||||
#include <curl/curl.h>
|
||||
|
||||
/** \brief Link type */
|
||||
typedef struct Link Link;
|
||||
|
||||
#include "cache.h"
|
||||
|
||||
/** \brief the link type */
|
||||
/**
|
||||
* \brief the link type
|
||||
*/
|
||||
typedef enum {
|
||||
LINK_HEAD = 'H',
|
||||
LINK_DIR = 'D',
|
||||
|
@ -23,34 +25,14 @@ typedef enum {
|
|||
LINK_UNINITIALISED_FILE = 'U'
|
||||
} LinkType;
|
||||
|
||||
/** \brief specify the type of data transfer */
|
||||
/**
|
||||
* \brief specify the type of data transfer
|
||||
*/
|
||||
typedef enum {
|
||||
FILESTAT = 's',
|
||||
DATA = 'd'
|
||||
} TransferType;
|
||||
|
||||
/** \brief For storing transfer data */
|
||||
typedef struct {
|
||||
/** \brief The array to store the data */
|
||||
char *data;
|
||||
/** \brief The size of the array */
|
||||
size_t size;
|
||||
/** \brief The minium requested size */
|
||||
size_t min_req_size;
|
||||
/** \brief The type of transfer being done */
|
||||
TransferType type;
|
||||
/** \brief Whether transfer is in progress */
|
||||
int transferring;
|
||||
/** \brief The link associated with the transfer */
|
||||
Link *link;
|
||||
} TransferStruct;
|
||||
|
||||
/**
|
||||
* \brief link table type
|
||||
* \details index 0 contains the Link for the base URL
|
||||
*/
|
||||
typedef struct LinkTable LinkTable;
|
||||
|
||||
/**
|
||||
* \brief Link type data structure
|
||||
*/
|
||||
|
@ -69,29 +51,35 @@ struct Link {
|
|||
long time;
|
||||
/** \brief The pointer associated with the cache file */
|
||||
Cache *cache_ptr;
|
||||
/**
|
||||
* \brief Sonic id field
|
||||
* \details This is used to store the followings:
|
||||
* - Arist ID
|
||||
* - Album ID
|
||||
* - Song ID
|
||||
* - Sub-directory ID (in the XML response, this is the ID on the "child"
|
||||
* element)
|
||||
*/
|
||||
char *sonic_id;
|
||||
/**
|
||||
* \brief Sonic directory depth
|
||||
* \details This is used exclusively in ID3 mode to store the depth of the
|
||||
* current directory.
|
||||
*/
|
||||
int sonic_depth;
|
||||
/** \brief Stores *sonic related data */
|
||||
Sonic sonic;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief link table type
|
||||
* \details index 0 contains the Link for the base URL
|
||||
*/
|
||||
struct LinkTable {
|
||||
int num;
|
||||
Link **links;
|
||||
};
|
||||
|
||||
/** \brief For storing transfer data */
|
||||
typedef struct {
|
||||
/** \brief The array to store the data */
|
||||
char *data;
|
||||
/** \brief The size of the array */
|
||||
size_t size;
|
||||
/** \brief The minium requested size */
|
||||
size_t min_req_size;
|
||||
/** \brief The type of transfer being done */
|
||||
TransferType type;
|
||||
/** \brief Whether transfer is in progress */
|
||||
int transferring;
|
||||
/** \brief The link associated with the transfer */
|
||||
Link *link;
|
||||
} TransferStruct;
|
||||
|
||||
/**
|
||||
* \brief root link table
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "config.h"
|
||||
#include "util.h"
|
||||
#include "cache.h"
|
||||
#include "fuse_local.h"
|
||||
#include "network.h"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "network.h"
|
||||
|
||||
#include "util.h"
|
||||
#include "cache.h"
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
|
|
22
src/sonic.c
22
src/sonic.c
|
@ -191,22 +191,22 @@ XML_parser_general(void *data, const char *elem, const char **attr)
|
|||
*/
|
||||
link->type = LINK_DIR;
|
||||
} else if (!strcmp(elem, "artist")
|
||||
&& linktbl->links[0]->sonic_depth != 3) {
|
||||
&& linktbl->links[0]->sonic.depth != 3) {
|
||||
/*
|
||||
* We want to skip the first "artist" element in the album table
|
||||
*/
|
||||
link = CALLOC(1, sizeof(Link));
|
||||
link->type = LINK_DIR;
|
||||
} else if (!strcmp(elem, "album")
|
||||
&& linktbl->links[0]->sonic_depth == 3) {
|
||||
&& linktbl->links[0]->sonic.depth == 3) {
|
||||
link = CALLOC(1, sizeof(Link));
|
||||
link->type = LINK_DIR;
|
||||
/*
|
||||
* The new table should be a level 4 song table
|
||||
*/
|
||||
link->sonic_depth = 4;
|
||||
link->sonic.depth = 4;
|
||||
} else if (!strcmp(elem, "song")
|
||||
&& linktbl->links[0]->sonic_depth == 4) {
|
||||
&& linktbl->links[0]->sonic.depth == 4) {
|
||||
link = CALLOC(1, sizeof(Link));
|
||||
link->type = LINK_FILE;
|
||||
} else {
|
||||
|
@ -224,8 +224,8 @@ XML_parser_general(void *data, const char *elem, const char **attr)
|
|||
char *suffix = "";
|
||||
for (int i = 0; attr[i]; i += 2) {
|
||||
if (!strcmp("id", attr[i])) {
|
||||
link->sonic_id = CALLOC(MAX_FILENAME_LEN + 1, sizeof(char));
|
||||
strncpy(link->sonic_id, attr[i + 1], MAX_FILENAME_LEN);
|
||||
link->sonic.id = CALLOC(MAX_FILENAME_LEN + 1, sizeof(char));
|
||||
strncpy(link->sonic.id, attr[i + 1], MAX_FILENAME_LEN);
|
||||
id_set = 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ XML_parser_general(void *data, const char *elem, const char **attr)
|
|||
}
|
||||
|
||||
if (link->type == LINK_FILE) {
|
||||
char *url = sonic_stream_link(link->sonic_id);
|
||||
char *url = sonic_stream_link(link->sonic.id);
|
||||
strncpy(link->f_url, url, MAX_PATH_LEN);
|
||||
FREE(url);
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ static LinkTable *sonic_url_to_LinkTable(const char *url,
|
|||
int depth)
|
||||
{
|
||||
LinkTable *linktbl = LinkTable_alloc(url);
|
||||
linktbl->links[0]->sonic_depth = depth;
|
||||
linktbl->links[0]->sonic.depth = depth;
|
||||
|
||||
/*
|
||||
* start downloading the base URL
|
||||
|
@ -429,7 +429,7 @@ XML_parser_id3_root(void *data, const char *elem, const char **attr)
|
|||
/*
|
||||
* The new table should be a level 3 album table
|
||||
*/
|
||||
link->sonic_depth = 3;
|
||||
link->sonic.depth = 3;
|
||||
for (int i = 0; attr[i]; i += 2) {
|
||||
if (!strcmp("name", attr[i])) {
|
||||
strncpy(link->linkname, attr[i + 1], MAX_FILENAME_LEN);
|
||||
|
@ -438,9 +438,9 @@ XML_parser_id3_root(void *data, const char *elem, const char **attr)
|
|||
}
|
||||
|
||||
if (!strcmp("id", attr[i])) {
|
||||
link->sonic_id =
|
||||
link->sonic.id =
|
||||
CALLOC(MAX_FILENAME_LEN + 1, sizeof(char));
|
||||
strncpy(link->sonic_id, attr[i + 1], MAX_FILENAME_LEN);
|
||||
strncpy(link->sonic.id, attr[i + 1], MAX_FILENAME_LEN);
|
||||
id_set = 1;
|
||||
continue;
|
||||
}
|
||||
|
|
19
src/sonic.h
19
src/sonic.h
|
@ -5,6 +5,25 @@
|
|||
* \brief Sonic related function
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
/**
|
||||
* \brief Sonic id field
|
||||
* \details This is used to store the followings:
|
||||
* - Arist ID
|
||||
* - Album ID
|
||||
* - Song ID
|
||||
* - Sub-directory ID (in the XML response, this is the ID on the "child"
|
||||
* element)
|
||||
*/
|
||||
char *id;
|
||||
/**
|
||||
* \brief Sonic directory depth
|
||||
* \details This is used exclusively in ID3 mode to store the depth of the
|
||||
* current directory.
|
||||
*/
|
||||
int depth;
|
||||
} Sonic;
|
||||
|
||||
#include "link.h"
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue