changed indentation style

This commit is contained in:
Fufu Fang 2021-08-31 11:18:39 +01:00
parent f791ceb308
commit 45d8cb8136
No known key found for this signature in database
GPG Key ID: 0F6BB5EF6F8BB729
16 changed files with 2546 additions and 2581 deletions

2
.gitignore vendored
View File

@ -12,3 +12,5 @@ doc
# Editor related # Editor related
*.kate-swp *.kate-swp
.vscode .vscode
*.c~
*.h~

View File

@ -3,4 +3,4 @@
- Static global variables: lower case letters - Static global variables: lower case letters
- Function names: TypeName_verb or verb_noun - Function names: TypeName_verb or verb_noun
- Type names: camel case with the first letter capitalised, e.g. CamelCase - Type names: camel case with the first letter capitalised, e.g. CamelCase
- Indentation style: ``indent -linux $SOURCE_FILES`` - Indentation style: ``indent -kr -nut *.c *.h``

View File

@ -119,8 +119,7 @@ void CacheSystem_init(const char *path, int url_supplied)
*/ */
sonic_path = path_append(META_DIR, "rest/"); sonic_path = path_append(META_DIR, "rest/");
if (mkdir if (mkdir
(sonic_path, (sonic_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
&& (errno != EEXIST)) { && (errno != EEXIST)) {
lprintf(fatal, "mkdir(): %s\n", strerror(errno)); lprintf(fatal, "mkdir(): %s\n", strerror(errno));
} }
@ -131,8 +130,7 @@ void CacheSystem_init(const char *path, int url_supplied)
*/ */
sonic_path = path_append(DATA_DIR, "rest/"); sonic_path = path_append(DATA_DIR, "rest/");
if (mkdir if (mkdir
(sonic_path, (sonic_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
&& (errno != EEXIST)) { && (errno != EEXIST)) {
lprintf(fatal, "mkdir(): %s\n", strerror(errno)); lprintf(fatal, "mkdir(): %s\n", strerror(errno));
} }
@ -256,8 +254,7 @@ static int Meta_write(Cache * cf)
* These things really should not be zero!!! * These things really should not be zero!!!
*/ */
if (!cf->content_length || !cf->blksz || !cf->segbc) { if (!cf->content_length || !cf->blksz || !cf->segbc) {
lprintf(error, lprintf(error, "Warning: content_length: %ld, blksz: %d, segbc: \
"Warning: content_length: %ld, blksz: %d, segbc: \
%ld\n", cf->content_length, cf->blksz, cf->segbc); %ld\n", cf->content_length, cf->blksz, cf->segbc);
} }
@ -370,14 +367,12 @@ static long Data_read(Cache * cf, uint8_t * buf, off_t len, off_t offset)
byte_read = fread(buf, sizeof(uint8_t), len, cf->dfp); byte_read = fread(buf, sizeof(uint8_t), len, cf->dfp);
if (byte_read != len) { if (byte_read != len) {
lprintf(debug, lprintf(debug,
"fread(): requested %ld, returned %ld!\n", "fread(): requested %ld, returned %ld!\n", len, byte_read);
len, byte_read);
if (feof(cf->dfp)) { if (feof(cf->dfp)) {
/* /*
* reached EOF * reached EOF
*/ */
lprintf(error, lprintf(error, "fread(): reached the end of the file!\n");
"fread(): reached the end of the file!\n");
} }
if (ferror(cf->dfp)) { if (ferror(cf->dfp)) {
/* /*
@ -405,7 +400,8 @@ static long Data_read(Cache * cf, uint8_t * buf, off_t len, off_t offset)
* - -1 when the data file does not exist * - -1 when the data file does not exist
* - otherwise, the number of bytes written. * - otherwise, the number of bytes written.
*/ */
static long Data_write(Cache * cf, const uint8_t * buf, off_t len, off_t offset) static long Data_write(Cache * cf, const uint8_t * buf, off_t len,
off_t offset)
{ {
if (len == 0) { if (len == 0) {
/* /*
@ -563,14 +559,12 @@ static int Cache_exist(const char *fn)
if (no_meta) { if (no_meta) {
lprintf(warning, "Cache file partially missing.\n"); lprintf(warning, "Cache file partially missing.\n");
if (unlink(datafn)) { if (unlink(datafn)) {
lprintf(error, "unlink(): %s\n", lprintf(error, "unlink(): %s\n", strerror(errno));
strerror(errno));
} }
} }
if (no_data) { if (no_data) {
if (unlink(metafn)) { if (unlink(metafn)) {
lprintf(error, "unlink(): %s\n", lprintf(error, "unlink(): %s\n", strerror(errno));
strerror(errno));
} }
} }
} }
@ -761,8 +755,7 @@ Cache *Cache_open(const char *fn)
if (Cache_exist(fn)) { if (Cache_exist(fn)) {
lprintf(cache_lock_debug, lprintf(cache_lock_debug,
"thread %x: unlocking cf_lock;\n", "thread %x: unlocking cf_lock;\n", pthread_self());
pthread_self());
PTHREAD_MUTEX_UNLOCK(&cf_lock); PTHREAD_MUTEX_UNLOCK(&cf_lock);
return NULL; return NULL;
} }
@ -770,8 +763,7 @@ Cache *Cache_open(const char *fn)
if (Cache_exist(link->sonic_id)) { if (Cache_exist(link->sonic_id)) {
lprintf(cache_lock_debug, lprintf(cache_lock_debug,
"thread %x: unlocking cf_lock;\n", "thread %x: unlocking cf_lock;\n", pthread_self());
pthread_self());
PTHREAD_MUTEX_UNLOCK(&cf_lock); PTHREAD_MUTEX_UNLOCK(&cf_lock);
return NULL; return NULL;
} }
@ -1015,12 +1007,10 @@ Cache_read(Cache * cf, char *const output_buf, const off_t len,
* download thread. Send it off and unlock the I/O * download thread. Send it off and unlock the I/O
*/ */
send = send =
Data_read(cf, (uint8_t *) output_buf, len, Data_read(cf, (uint8_t *) output_buf, len, offset_start);
offset_start);
lprintf(cache_lock_debug, lprintf(cache_lock_debug,
"thread %x: unlocking w_lock;\n", "thread %x: unlocking w_lock;\n", pthread_self());
pthread_self());
PTHREAD_MUTEX_UNLOCK(&cf->w_lock); PTHREAD_MUTEX_UNLOCK(&cf->w_lock);
goto bgdl; goto bgdl;
@ -1075,8 +1065,7 @@ error.\n", recv, cf->blksz);
*/ */
if (!pthread_mutex_trylock(&cf->bgt_lock)) { if (!pthread_mutex_trylock(&cf->bgt_lock)) {
lprintf(cache_lock_debug, lprintf(cache_lock_debug,
"thread %x: trylocked bgt_lock;\n", "thread %x: trylocked bgt_lock;\n", pthread_self());
pthread_self());
cf->next_dl_offset = next_dl_offset; cf->next_dl_offset = next_dl_offset;
if (pthread_create(&cf->bgt, NULL, Cache_bgdl, cf)) { if (pthread_create(&cf->bgt, NULL, Cache_bgdl, cf)) {
lprintf(error, lprintf(error,

View File

@ -96,7 +96,8 @@ LinkTable *LinkSystem_init(const char *raw_url)
void LinkTable_add(LinkTable * linktbl, Link * link) void LinkTable_add(LinkTable * linktbl, Link * link)
{ {
linktbl->num++; linktbl->num++;
linktbl->links = realloc(linktbl->links, linktbl->num * sizeof(Link *)); linktbl->links =
realloc(linktbl->links, linktbl->num * sizeof(Link *));
if (!linktbl->links) { if (!linktbl->links) {
lprintf(fatal, "realloc() failure!\n"); lprintf(fatal, "realloc() failure!\n");
} }
@ -166,10 +167,8 @@ static int linknames_equal(char *linkname, const char *linkname_new)
*/ */
if (!strncmp if (!strncmp
(linkname, linkname_new, strnlen(linkname, MAX_FILENAME_LEN))) { (linkname, linkname_new, strnlen(linkname, MAX_FILENAME_LEN))) {
size_t linkname_new_len = size_t linkname_new_len = strnlen(linkname_new, MAX_FILENAME_LEN);
strnlen(linkname_new, MAX_FILENAME_LEN); if ((linkname_new_len - strnlen(linkname, MAX_FILENAME_LEN) == 1)
if ((linkname_new_len - strnlen(linkname, MAX_FILENAME_LEN) ==
1)
&& (linkname_new[linkname_new_len - 1] == '/')) { && (linkname_new[linkname_new_len - 1] == '/')) {
return 1; return 1;
} }
@ -188,7 +187,8 @@ static void HTML_to_LinkTable(GumboNode * node, LinkTable * linktbl)
} }
GumboAttribute *href; GumboAttribute *href;
if (node->v.element.tag == GUMBO_TAG_A && if (node->v.element.tag == GUMBO_TAG_A &&
(href = gumbo_get_attribute(&node->v.element.attributes, "href"))) { (href =
gumbo_get_attribute(&node->v.element.attributes, "href"))) {
/* /*
* if it is valid, copy the link onto the heap * if it is valid, copy the link onto the heap
*/ */
@ -370,8 +370,7 @@ static void LinkTable_fill(LinkTable * linktbl)
CURL *c = curl_easy_init(); CURL *c = curl_easy_init();
unescaped_linkname = curl_easy_unescape(c, this_link->linkname, unescaped_linkname = curl_easy_unescape(c, this_link->linkname,
0, NULL); 0, NULL);
strncpy(this_link->linkname, unescaped_linkname, strncpy(this_link->linkname, unescaped_linkname, MAX_FILENAME_LEN);
MAX_FILENAME_LEN);
curl_free(unescaped_linkname); curl_free(unescaped_linkname);
curl_easy_cleanup(c); curl_easy_cleanup(c);
} }
@ -455,8 +454,7 @@ DataStruct Link_to_DataStruct(Link * head_link)
sleep(CONFIG.http_wait_sec); sleep(CONFIG.http_wait_sec);
} else if (http_resp != HTTP_OK) { } else if (http_resp != HTTP_OK) {
lprintf(warning, lprintf(warning,
"cannot retrieve URL: %s, HTTP %ld\n", "cannot retrieve URL: %s, HTTP %ld\n", url, http_resp);
url, http_resp);
buf.size = 0; buf.size = 0;
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
return buf; return buf;
@ -507,7 +505,8 @@ LinkTable *LinkTable_new(const char *url)
int skip_fill = 0; int skip_fill = 0;
char *unescaped_path; char *unescaped_path;
CURL *c = curl_easy_init(); CURL *c = curl_easy_init();
unescaped_path = curl_easy_unescape(c, url + ROOT_LINK_OFFSET, 0, NULL); unescaped_path =
curl_easy_unescape(c, url + ROOT_LINK_OFFSET, 0, NULL);
if (CACHE_SYSTEM_INIT) { if (CACHE_SYSTEM_INIT) {
CacheDir_create(unescaped_path); CacheDir_create(unescaped_path);
LinkTable *disk_linktbl; LinkTable *disk_linktbl;
@ -590,11 +589,9 @@ int LinkTable_disk_save(LinkTable * linktbl, const char *dirn)
for (int i = 0; i < linktbl->num; i++) { for (int i = 0; i < linktbl->num; i++) {
fwrite(linktbl->links[i]->linkname, sizeof(char), fwrite(linktbl->links[i]->linkname, sizeof(char),
MAX_FILENAME_LEN, fp); MAX_FILENAME_LEN, fp);
fwrite(linktbl->links[i]->f_url, sizeof(char), MAX_PATH_LEN, fwrite(linktbl->links[i]->f_url, sizeof(char), MAX_PATH_LEN, fp);
fp);
fwrite(&linktbl->links[i]->type, sizeof(LinkType), 1, fp); fwrite(&linktbl->links[i]->type, sizeof(LinkType), 1, fp);
fwrite(&linktbl->links[i]->content_length, sizeof(size_t), 1, fwrite(&linktbl->links[i]->content_length, sizeof(size_t), 1, fp);
fp);
fwrite(&linktbl->links[i]->time, sizeof(long), 1, fp); fwrite(&linktbl->links[i]->time, sizeof(long), 1, fp);
} }
@ -641,8 +638,7 @@ LinkTable *LinkTable_disk_open(const char *dirn)
MAX_FILENAME_LEN, fp); MAX_FILENAME_LEN, fp);
fread(linktbl->links[i]->f_url, sizeof(char), MAX_PATH_LEN, fp); fread(linktbl->links[i]->f_url, sizeof(char), MAX_PATH_LEN, fp);
fread(&linktbl->links[i]->type, sizeof(LinkType), 1, fp); fread(&linktbl->links[i]->type, sizeof(LinkType), 1, fp);
fread(&linktbl->links[i]->content_length, sizeof(size_t), 1, fread(&linktbl->links[i]->content_length, sizeof(size_t), 1, fp);
fp);
fread(&linktbl->links[i]->time, sizeof(long), 1, fp); fread(&linktbl->links[i]->time, sizeof(long), 1, fp);
if (feof(fp)) { if (feof(fp)) {
/* /*
@ -676,8 +672,7 @@ LinkTable *path_to_Link_LinkTable_new(const char *path)
next_table = LinkTable_new(link->f_url); next_table = LinkTable_new(link->f_url);
} else if (CONFIG.mode == SONIC) { } else if (CONFIG.mode == SONIC) {
if (!CONFIG.sonic_id3) { if (!CONFIG.sonic_id3) {
next_table = next_table = sonic_LinkTable_new_index(link->sonic_id);
sonic_LinkTable_new_index(link->sonic_id);
} else { } else {
next_table = next_table =
sonic_LinkTable_new_id3(link->sonic_depth, sonic_LinkTable_new_id3(link->sonic_depth,
@ -715,8 +710,7 @@ 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 if (!strncmp
(path, linktbl->links[i]->linkname, (path, linktbl->links[i]->linkname, MAX_FILENAME_LEN)) {
MAX_FILENAME_LEN)) {
/* /*
* We found our link * We found our link
*/ */
@ -740,40 +734,33 @@ static Link *path_to_Link_recursive(char *path, LinkTable * linktbl)
char *next_path = slash + 1; char *next_path = slash + 1;
for (int i = 1; i < linktbl->num; i++) { for (int i = 1; i < linktbl->num; i++) {
if (!strncmp if (!strncmp
(path, linktbl->links[i]->linkname, (path, linktbl->links[i]->linkname, MAX_FILENAME_LEN)) {
MAX_FILENAME_LEN)) {
/* /*
* The next sub-directory exists * The next sub-directory exists
*/ */
LinkTable *next_table = LinkTable *next_table = linktbl->links[i]->next_table;
linktbl->links[i]->next_table;
if (!next_table) { if (!next_table) {
if (CONFIG.mode == NORMAL) { if (CONFIG.mode == NORMAL) {
next_table = next_table =
LinkTable_new(linktbl->links LinkTable_new(linktbl->links[i]->f_url);
[i]->f_url);
} else if (CONFIG.mode == SONIC) { } else if (CONFIG.mode == SONIC) {
if (!CONFIG.sonic_id3) { if (!CONFIG.sonic_id3) {
next_table = next_table =
sonic_LinkTable_new_index sonic_LinkTable_new_index
(linktbl->links (linktbl->links[i]->sonic_id);
[i]->sonic_id);
} else { } else {
next_table = next_table =
sonic_LinkTable_new_id3 sonic_LinkTable_new_id3
(linktbl->links (linktbl->links
[i]->sonic_depth, [i]->sonic_depth,
linktbl->links linktbl->links[i]->sonic_id);
[i]->sonic_id);
} }
} else { } else {
lprintf(fatal, lprintf(fatal, "Invalid CONFIG.mode\n");
"Invalid CONFIG.mode\n");
} }
} }
linktbl->links[i]->next_table = next_table; linktbl->links[i]->next_table = next_table;
return path_to_Link_recursive(next_path, return path_to_Link_recursive(next_path, next_table);
next_table);
} }
} }
} }
@ -800,7 +787,8 @@ Link *path_to_Link(const char *path)
} }
long long
path_download(const char *path, char *output_buf, size_t size, off_t offset) path_download(const char *path, char *output_buf, size_t size,
off_t offset)
{ {
if (!path) { if (!path) {
lprintf(fatal, "\npath_download(): NULL path supplied\n"); lprintf(fatal, "\npath_download(): NULL path supplied\n");

View File

@ -90,7 +90,8 @@ int main(int argc, char **argv)
* The second last remaining argument is the URL * The second last remaining argument is the URL
*/ */
char *base_url = argv[argc - 2]; char *base_url = argv[argc - 2];
if (strncmp(base_url, "http://", 7) && strncmp(base_url, "https://", 8)) { if (strncmp(base_url, "http://", 7)
&& strncmp(base_url, "https://", 8)) {
fprintf(stderr, "Error: Please supply a valid URL.\n"); fprintf(stderr, "Error: Please supply a valid URL.\n");
print_help(argv[0], 0); print_help(argv[0], 0);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -123,8 +124,7 @@ void parse_config_file(char ***argv, int *argc)
if (!xdg_config_home) { if (!xdg_config_home) {
char *home = getenv("HOME"); char *home = getenv("HOME");
char *xdg_config_home_default = "/.config"; char *xdg_config_home_default = "/.config";
xdg_config_home = xdg_config_home = path_append(home, xdg_config_home_default);
path_append(home, xdg_config_home_default);
} }
full_path = path_append(xdg_config_home, "/httpdirfs/config"); full_path = path_append(xdg_config_home, "/httpdirfs/config");
} else { } else {
@ -145,28 +145,21 @@ void parse_config_file(char ***argv, int *argc)
char *space; char *space;
space = strchr(buf, ' '); space = strchr(buf, ' ');
if (!space) { if (!space) {
*argv = *argv = realloc(*argv, *argc * sizeof(char **));
realloc(*argv, (*argv)[*argc - 1] = strndup(buf, buf_len);
*argc * sizeof(char **));
(*argv)[*argc - 1] =
strndup(buf, buf_len);
} else { } else {
(*argc)++; (*argc)++;
*argv = *argv = realloc(*argv, *argc * sizeof(char **));
realloc(*argv,
*argc * sizeof(char **));
/* /*
* Only copy up to the space character * Only copy up to the space character
*/ */
(*argv)[*argc - 2] = (*argv)[*argc - 2] = strndup(buf, space - buf);
strndup(buf, space - buf);
/* /*
* Starts copying after the space * Starts copying after the space
*/ */
(*argv)[*argc - 1] = strndup(space + 1, (*argv)[*argc - 1] = strndup(space + 1,
buf_len - buf_len -
(space + (space + 1 - buf));
1 - buf));
} }
} }
} }

View File

@ -229,8 +229,7 @@ int curl_multi_perform_once(void)
if (maxfd == -1) { if (maxfd == -1) {
usleep(100 * 1000); usleep(100 * 1000);
} else { } else {
if (select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout) < if (select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout) < 0) {
0) {
lprintf(error, "select(): %s.\n", strerror(errno)); lprintf(error, "select(): %s.\n", strerror(errno));
} }
} }
@ -354,7 +353,8 @@ void transfer_nonblocking(CURL * curl)
} }
size_t size_t
write_memory_callback(void *contents, size_t size, size_t nmemb, void *userp) write_memory_callback(void *contents, size_t size, size_t nmemb,
void *userp)
{ {
size_t realsize = size * nmemb; size_t realsize = size * nmemb;
DataStruct *mem = (DataStruct *) userp; DataStruct *mem = (DataStruct *) userp;

View File

@ -35,7 +35,8 @@ void transfer_nonblocking(CURL * curl);
/** \brief callback function for file transfer */ /** \brief callback function for file transfer */
size_t size_t
write_memory_callback(void *contents, size_t size, size_t nmemb, void *userp); write_memory_callback(void *contents, size_t size, size_t nmemb,
void *userp);
/** /**
* \brief check if a HTTP response code corresponds to a temporary failure * \brief check if a HTTP response code corresponds to a temporary failure

View File

@ -63,8 +63,7 @@ static char *sonic_gen_auth_str(void)
{ {
if (!CONFIG.sonic_insecure) { if (!CONFIG.sonic_insecure) {
char *salt = generate_salt(); char *salt = generate_salt();
size_t pwd_len = size_t pwd_len = strnlen(SONIC_CONFIG.password, MAX_FILENAME_LEN);
strnlen(SONIC_CONFIG.password, MAX_FILENAME_LEN);
size_t pwd_salt_len = pwd_len + strnlen(salt, MAX_FILENAME_LEN); size_t pwd_salt_len = pwd_len + strnlen(salt, MAX_FILENAME_LEN);
char *pwd_salt = CALLOC(pwd_salt_len + 1, sizeof(char)); char *pwd_salt = CALLOC(pwd_salt_len + 1, sizeof(char));
strncat(pwd_salt, SONIC_CONFIG.password, MAX_FILENAME_LEN); strncat(pwd_salt, SONIC_CONFIG.password, MAX_FILENAME_LEN);
@ -206,7 +205,8 @@ XML_parser_general(void *data, const char *elem, const char **attr)
* The new table should be a level 4 song table * 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) { } else if (!strcmp(elem, "song")
&& linktbl->links[0]->sonic_depth == 4) {
link = CALLOC(1, sizeof(Link)); link = CALLOC(1, sizeof(Link));
link->type = LINK_FILE; link->type = LINK_FILE;
} else { } else {
@ -224,8 +224,7 @@ XML_parser_general(void *data, const char *elem, const char **attr)
char *suffix = ""; char *suffix = "";
for (int i = 0; attr[i]; i += 2) { for (int i = 0; attr[i]; i += 2) {
if (!strcmp("id", attr[i])) { if (!strcmp("id", attr[i])) {
link->sonic_id = link->sonic_id = CALLOC(MAX_FILENAME_LEN + 1, sizeof(char));
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; id_set = 1;
continue; continue;
@ -238,11 +237,9 @@ XML_parser_general(void *data, const char *elem, const char **attr)
*/ */
char *s = strrchr(attr[i + 1], '/'); char *s = strrchr(attr[i + 1], '/');
if (s) { if (s) {
strncpy(link->linkname, s + 1, strncpy(link->linkname, s + 1, MAX_FILENAME_LEN);
MAX_FILENAME_LEN);
} else { } else {
strncpy(link->linkname, attr[i + 1], strncpy(link->linkname, attr[i + 1], MAX_FILENAME_LEN);
MAX_FILENAME_LEN);
} }
linkname_set = 1; linkname_set = 1;
continue; continue;
@ -256,8 +253,7 @@ XML_parser_general(void *data, const char *elem, const char **attr)
if (!linkname_set) { if (!linkname_set) {
if (!strcmp("title", attr[i]) if (!strcmp("title", attr[i])
|| !strcmp("name", attr[i])) { || !strcmp("name", attr[i])) {
strncpy(link->linkname, attr[i + 1], strncpy(link->linkname, attr[i + 1], MAX_FILENAME_LEN);
MAX_FILENAME_LEN);
linkname_set = 1; linkname_set = 1;
continue; continue;
} }
@ -371,7 +367,8 @@ LinkTable *sonic_LinkTable_new_index(const char *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_general, 0); LinkTable *linktbl =
sonic_url_to_LinkTable(url, XML_parser_general, 0);
FREE(url); FREE(url);
return linktbl; return linktbl;
} }
@ -408,8 +405,7 @@ XML_parser_id3_root(void *data, const char *elem, const char **attr)
link->type = LINK_DIR; link->type = LINK_DIR;
for (int i = 0; attr[i]; i += 2) { for (int i = 0; attr[i]; i += 2) {
if (!strcmp("name", attr[i])) { if (!strcmp("name", attr[i])) {
strncpy(link->linkname, attr[i + 1], strncpy(link->linkname, attr[i + 1], MAX_FILENAME_LEN);
MAX_FILENAME_LEN);
linkname_set = 1; linkname_set = 1;
/* /*
* Allocate a new LinkTable * Allocate a new LinkTable
@ -435,8 +431,7 @@ XML_parser_id3_root(void *data, const char *elem, const char **attr)
link->sonic_depth = 3; link->sonic_depth = 3;
for (int i = 0; attr[i]; i += 2) { for (int i = 0; attr[i]; i += 2) {
if (!strcmp("name", attr[i])) { if (!strcmp("name", attr[i])) {
strncpy(link->linkname, attr[i + 1], strncpy(link->linkname, attr[i + 1], MAX_FILENAME_LEN);
MAX_FILENAME_LEN);
linkname_set = 1; linkname_set = 1;
continue; continue;
} }
@ -444,8 +439,7 @@ XML_parser_id3_root(void *data, const char *elem, const char **attr)
if (!strcmp("id", attr[i])) { if (!strcmp("id", attr[i])) {
link->sonic_id = link->sonic_id =
CALLOC(MAX_FILENAME_LEN + 1, sizeof(char)); CALLOC(MAX_FILENAME_LEN + 1, sizeof(char));
strncpy(link->sonic_id, attr[i + 1], strncpy(link->sonic_id, attr[i + 1], MAX_FILENAME_LEN);
MAX_FILENAME_LEN);
id_set = 1; id_set = 1;
continue; continue;
} }
@ -485,8 +479,7 @@ LinkTable *sonic_LinkTable_new_id3(int depth, const char *id)
*/ */
case 3: case 3:
url = sonic_getArtist_link(id); url = sonic_getArtist_link(id);
linktbl = linktbl = sonic_url_to_LinkTable(url, XML_parser_general, depth);
sonic_url_to_LinkTable(url, XML_parser_general, depth);
FREE(url); FREE(url);
break; break;
/* /*
@ -494,8 +487,7 @@ LinkTable *sonic_LinkTable_new_id3(int depth, const char *id)
*/ */
case 4: case 4:
url = sonic_getAlbum_link(id); url = sonic_getAlbum_link(id);
linktbl = linktbl = sonic_url_to_LinkTable(url, XML_parser_general, depth);
sonic_url_to_LinkTable(url, XML_parser_general, depth);
FREE(url); FREE(url);
break; break;
default: default: