more refactoring
This commit is contained in:
parent
bc88a681e3
commit
cd6bb5bee8
3
Makefile
3
Makefile
|
@ -63,11 +63,12 @@ doc:
|
||||||
doxygen Doxyfile
|
doxygen Doxyfile
|
||||||
|
|
||||||
format:
|
format:
|
||||||
indent -kr -nut src/*.c src/*.h
|
astyle --style=kr --align-pointer=name src/*.c src/*.h
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -f src/*.h~
|
-rm -f src/*.h~
|
||||||
-rm -f src/*.c~
|
-rm -f src/*.c~
|
||||||
|
-rm -f src/*orig
|
||||||
-rm -f *.o
|
-rm -f *.o
|
||||||
-rm -f httpdirfs
|
-rm -f httpdirfs
|
||||||
|
|
||||||
|
|
63
src/cache.c
63
src/cache.c
|
@ -46,14 +46,14 @@ static char *CacheSystem_calc_dir(const char *url)
|
||||||
xdg_cache_home = path_append(home, xdg_cache_home_default);
|
xdg_cache_home = path_append(home, xdg_cache_home_default);
|
||||||
}
|
}
|
||||||
if (mkdir
|
if (mkdir
|
||||||
(xdg_cache_home, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
|
(xdg_cache_home, 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));
|
||||||
}
|
}
|
||||||
char *cache_dir_root = path_append(xdg_cache_home, "/httpdirfs/");
|
char *cache_dir_root = path_append(xdg_cache_home, "/httpdirfs/");
|
||||||
if (mkdir
|
if (mkdir
|
||||||
(cache_dir_root, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
|
(cache_dir_root, 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ static char *CacheSystem_calc_dir(const char *url)
|
||||||
char *escaped_url = curl_easy_escape(c, url, 0);
|
char *escaped_url = curl_easy_escape(c, url, 0);
|
||||||
char *full_path = path_append(cache_dir_root, escaped_url);
|
char *full_path = path_append(cache_dir_root, escaped_url);
|
||||||
if (mkdir(full_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
|
if (mkdir(full_path, 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));
|
||||||
}
|
}
|
||||||
FREE(fn);
|
FREE(fn);
|
||||||
|
@ -107,12 +107,12 @@ void CacheSystem_init(const char *path, int url_supplied)
|
||||||
* Check if directories exist, if not, create them
|
* Check if directories exist, if not, create them
|
||||||
*/
|
*/
|
||||||
if (mkdir(META_DIR, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
|
if (mkdir(META_DIR, 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mkdir(DATA_DIR, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
|
if (mkdir(DATA_DIR, 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,8 +123,8 @@ 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, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
|
(sonic_path, 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));
|
||||||
}
|
}
|
||||||
FREE(sonic_path);
|
FREE(sonic_path);
|
||||||
|
@ -134,8 +134,8 @@ 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, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
|
(sonic_path, 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));
|
||||||
}
|
}
|
||||||
FREE(sonic_path);
|
FREE(sonic_path);
|
||||||
|
@ -148,7 +148,7 @@ void CacheSystem_init(const char *path, int url_supplied)
|
||||||
* \brief read a metadata file
|
* \brief read a metadata file
|
||||||
* \return 0 on success, errno on error.
|
* \return 0 on success, errno on error.
|
||||||
*/
|
*/
|
||||||
static int Meta_read(Cache * cf)
|
static int Meta_read(Cache *cf)
|
||||||
{
|
{
|
||||||
FILE *fp = cf->mfp;
|
FILE *fp = cf->mfp;
|
||||||
rewind(fp);
|
rewind(fp);
|
||||||
|
@ -236,7 +236,7 @@ file!\n");
|
||||||
* - -1 on error,
|
* - -1 on error,
|
||||||
* - 0 on success
|
* - 0 on success
|
||||||
*/
|
*/
|
||||||
static int Meta_write(Cache * cf)
|
static int Meta_write(Cache *cf)
|
||||||
{
|
{
|
||||||
FILE *fp = cf->mfp;
|
FILE *fp = cf->mfp;
|
||||||
rewind(fp);
|
rewind(fp);
|
||||||
|
@ -279,7 +279,7 @@ static int Meta_write(Cache * cf)
|
||||||
* \details We use sparse creation here
|
* \details We use sparse creation here
|
||||||
* \return exit on failure
|
* \return exit on failure
|
||||||
*/
|
*/
|
||||||
static void Data_create(Cache * cf)
|
static void Data_create(Cache *cf)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int mode;
|
int mode;
|
||||||
|
@ -326,7 +326,7 @@ static long Data_size(const char *fn)
|
||||||
* - negative values on error,
|
* - negative values on error,
|
||||||
* - otherwise, the number of bytes read.
|
* - otherwise, the number of bytes read.
|
||||||
*/
|
*/
|
||||||
static long Data_read(Cache * cf, uint8_t * buf, off_t len, off_t offset)
|
static long Data_read(Cache *cf, uint8_t *buf, off_t len, off_t offset)
|
||||||
{
|
{
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
lprintf(error, "requested to read 0 byte!\n");
|
lprintf(error, "requested to read 0 byte!\n");
|
||||||
|
@ -379,7 +379,7 @@ static long Data_read(Cache * cf, uint8_t * buf, off_t len, off_t offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
|
||||||
lprintf(cache_lock_debug,
|
lprintf(cache_lock_debug,
|
||||||
"thread %x: unlocking seek_lock;\n", pthread_self());
|
"thread %x: unlocking seek_lock;\n", pthread_self());
|
||||||
|
@ -397,7 +397,7 @@ 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,
|
static long Data_write(Cache *cf, const uint8_t *buf, off_t len,
|
||||||
off_t offset)
|
off_t offset)
|
||||||
{
|
{
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
|
@ -437,7 +437,7 @@ static long Data_write(Cache * cf, const uint8_t * buf, off_t len,
|
||||||
lprintf(error, "fwrite(): encountered error!\n");
|
lprintf(error, "fwrite(): encountered error!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
lprintf(cache_lock_debug,
|
lprintf(cache_lock_debug,
|
||||||
"thread %x: unlocking seek_lock;\n", pthread_self());
|
"thread %x: unlocking seek_lock;\n", pthread_self());
|
||||||
PTHREAD_MUTEX_UNLOCK(&cf->seek_lock);
|
PTHREAD_MUTEX_UNLOCK(&cf->seek_lock);
|
||||||
|
@ -499,7 +499,7 @@ static Cache *Cache_alloc()
|
||||||
/**
|
/**
|
||||||
* \brief free a cache data structure
|
* \brief free a cache data structure
|
||||||
*/
|
*/
|
||||||
static void Cache_free(Cache * cf)
|
static void Cache_free(Cache *cf)
|
||||||
{
|
{
|
||||||
if (pthread_mutex_destroy(&cf->seek_lock)) {
|
if (pthread_mutex_destroy(&cf->seek_lock)) {
|
||||||
lprintf(fatal, "could not destroy seek_lock!\n");
|
lprintf(fatal, "could not destroy seek_lock!\n");
|
||||||
|
@ -605,7 +605,7 @@ void Cache_delete(const char *fn)
|
||||||
* - 0 on success
|
* - 0 on success
|
||||||
* - -1 on failure, with appropriate errno set.
|
* - -1 on failure, with appropriate errno set.
|
||||||
*/
|
*/
|
||||||
static int Data_open(Cache * cf)
|
static int Data_open(Cache *cf)
|
||||||
{
|
{
|
||||||
char *datafn = path_append(DATA_DIR, cf->path);
|
char *datafn = path_append(DATA_DIR, cf->path);
|
||||||
cf->dfp = fopen(datafn, "r+");
|
cf->dfp = fopen(datafn, "r+");
|
||||||
|
@ -627,7 +627,7 @@ static int Data_open(Cache * cf)
|
||||||
* - 0 on success
|
* - 0 on success
|
||||||
* - -1 on failure, with appropriate errno set.
|
* - -1 on failure, with appropriate errno set.
|
||||||
*/
|
*/
|
||||||
static int Meta_open(Cache * cf)
|
static int Meta_open(Cache *cf)
|
||||||
{
|
{
|
||||||
char *metafn = path_append(META_DIR, cf->path);
|
char *metafn = path_append(META_DIR, cf->path);
|
||||||
cf->mfp = fopen(metafn, "r+");
|
cf->mfp = fopen(metafn, "r+");
|
||||||
|
@ -647,7 +647,7 @@ static int Meta_open(Cache * cf)
|
||||||
* \brief Create a metafile
|
* \brief Create a metafile
|
||||||
* \return exit on error
|
* \return exit on error
|
||||||
*/
|
*/
|
||||||
static void Meta_create(Cache * cf)
|
static void Meta_create(Cache *cf)
|
||||||
{
|
{
|
||||||
char *metafn = path_append(META_DIR, cf->path);
|
char *metafn = path_append(META_DIR, cf->path);
|
||||||
cf->mfp = fopen(metafn, "w");
|
cf->mfp = fopen(metafn, "w");
|
||||||
|
@ -869,7 +869,7 @@ cf->content_length: %ld, Data_size(fn): %ld.\n", fn, cf->content_length, Data_si
|
||||||
return cf;
|
return cf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cache_close(Cache * cf)
|
void Cache_close(Cache *cf)
|
||||||
{
|
{
|
||||||
lprintf(cache_lock_debug,
|
lprintf(cache_lock_debug,
|
||||||
"thread %x: locking cf_lock;\n", pthread_self());
|
"thread %x: locking cf_lock;\n", pthread_self());
|
||||||
|
@ -909,7 +909,7 @@ void Cache_close(Cache * cf)
|
||||||
* \brief Check if a segment exists.
|
* \brief Check if a segment exists.
|
||||||
* \return 1 if the segment exists
|
* \return 1 if the segment exists
|
||||||
*/
|
*/
|
||||||
static int Seg_exist(Cache * cf, off_t offset)
|
static int Seg_exist(Cache *cf, off_t offset)
|
||||||
{
|
{
|
||||||
off_t byte = offset / cf->blksz;
|
off_t byte = offset / cf->blksz;
|
||||||
return cf->seg[byte];
|
return cf->seg[byte];
|
||||||
|
@ -922,7 +922,7 @@ static int Seg_exist(Cache * cf, off_t offset)
|
||||||
* \param[in] i 1 for exist, 0 for doesn't exist
|
* \param[in] i 1 for exist, 0 for doesn't exist
|
||||||
* \note Call this after downloading a segment.
|
* \note Call this after downloading a segment.
|
||||||
*/
|
*/
|
||||||
static void Seg_set(Cache * cf, off_t offset, int i)
|
static void Seg_set(Cache *cf, off_t offset, int i)
|
||||||
{
|
{
|
||||||
off_t byte = offset / cf->blksz;
|
off_t byte = offset / cf->blksz;
|
||||||
cf->seg[byte] = i;
|
cf->seg[byte] = i;
|
||||||
|
@ -952,8 +952,8 @@ which does't make sense\n", pthread_self(), recv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((recv == cf->blksz) ||
|
if ((recv == cf->blksz) ||
|
||||||
(cf->next_dl_offset ==
|
(cf->next_dl_offset ==
|
||||||
(cf->content_length / cf->blksz * cf->blksz))) {
|
(cf->content_length / cf->blksz * cf->blksz))) {
|
||||||
Data_write(cf, recv_buf, recv, cf->next_dl_offset);
|
Data_write(cf, recv_buf, recv, cf->next_dl_offset);
|
||||||
Seg_set(cf, cf->next_dl_offset, 1);
|
Seg_set(cf, cf->next_dl_offset, 1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -976,7 +976,7 @@ error.\n", recv, cf->blksz);
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
long
|
||||||
Cache_read(Cache * cf, char *const output_buf, const off_t len,
|
Cache_read(Cache *cf, char *const output_buf, const off_t len,
|
||||||
const off_t offset_start)
|
const off_t offset_start)
|
||||||
{
|
{
|
||||||
long send;
|
long send;
|
||||||
|
@ -1036,7 +1036,7 @@ which does't make sense\n", pthread_self(), recv);
|
||||||
* Condition 2: offset is the last segment
|
* Condition 2: offset is the last segment
|
||||||
*/
|
*/
|
||||||
if ((recv == cf->blksz) ||
|
if ((recv == cf->blksz) ||
|
||||||
(dl_offset == (cf->content_length / cf->blksz * cf->blksz))) {
|
(dl_offset == (cf->content_length / cf->blksz * cf->blksz))) {
|
||||||
Data_write(cf, recv_buf, recv, dl_offset);
|
Data_write(cf, recv_buf, recv, dl_offset);
|
||||||
Seg_set(cf, dl_offset, 1);
|
Seg_set(cf, dl_offset, 1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1053,12 +1053,11 @@ error.\n", recv, cf->blksz);
|
||||||
/*
|
/*
|
||||||
* ----------- Download the next segment in background -----------------
|
* ----------- Download the next segment in background -----------------
|
||||||
*/
|
*/
|
||||||
bgdl:
|
bgdl: {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
off_t next_dl_offset = round_div(offset_start, cf->blksz) * cf->blksz;
|
off_t next_dl_offset = round_div(offset_start, cf->blksz) * cf->blksz;
|
||||||
if ((next_dl_offset > dl_offset) && !Seg_exist(cf, next_dl_offset)
|
if ((next_dl_offset > dl_offset) && !Seg_exist(cf, next_dl_offset)
|
||||||
&& next_dl_offset < cf->content_length) {
|
&& next_dl_offset < cf->content_length) {
|
||||||
/*
|
/*
|
||||||
* Stop the spawning of multiple background pthreads
|
* Stop the spawning of multiple background pthreads
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -118,7 +118,7 @@ Cache *Cache_open(const char *fn);
|
||||||
* \brief Close a cache data structure
|
* \brief Close a cache data structure
|
||||||
* \note This function is called by fs_release()
|
* \note This function is called by fs_release()
|
||||||
*/
|
*/
|
||||||
void Cache_close(Cache * cf);
|
void Cache_close(Cache *cf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief create a cache file set if it doesn't exist already
|
* \brief create a cache file set if it doesn't exist already
|
||||||
|
@ -146,6 +146,6 @@ void Cache_delete(const char *fn);
|
||||||
* \return the length of the segment the cache system managed to obtain.
|
* \return the length of the segment the cache system managed to obtain.
|
||||||
* \note Called by fs_read(), verified to be working
|
* \note Called by fs_read(), verified to be working
|
||||||
*/
|
*/
|
||||||
long Cache_read(Cache * cf, char *const output_buf, const off_t len,
|
long Cache_read(Cache *cf, char *const output_buf, const off_t len,
|
||||||
const off_t offset_start);
|
const off_t offset_start);
|
||||||
#endif
|
#endif
|
||||||
|
|
110
src/link.c
110
src/link.c
|
@ -52,7 +52,7 @@ static Link *Link_new(const char *linkname, LinkType type)
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CURL *Link_to_curl(Link * link)
|
static CURL *Link_to_curl(Link *link)
|
||||||
{
|
{
|
||||||
CURL *curl = curl_easy_init();
|
CURL *curl = curl_easy_init();
|
||||||
if (!curl) {
|
if (!curl) {
|
||||||
|
@ -155,7 +155,7 @@ static CURL *Link_to_curl(Link * link)
|
||||||
return curl;
|
return curl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Link_req_file_stat(Link * this_link)
|
static void Link_req_file_stat(Link *this_link)
|
||||||
{
|
{
|
||||||
CURL *curl = Link_to_curl(this_link);
|
CURL *curl = Link_to_curl(this_link);
|
||||||
CURLcode ret = curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
|
CURLcode ret = curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
|
||||||
|
@ -190,7 +190,7 @@ static void Link_req_file_stat(Link * this_link)
|
||||||
* \details Try and get the stats for each link in the link table. This will get
|
* \details Try and get the stats for each link in the link table. This will get
|
||||||
* repeated until the uninitialised entry count drop to zero.
|
* repeated until the uninitialised entry count drop to zero.
|
||||||
*/
|
*/
|
||||||
static void LinkTable_uninitialised_fill(LinkTable * linktbl)
|
static void LinkTable_uninitialised_fill(LinkTable *linktbl)
|
||||||
{
|
{
|
||||||
int u;
|
int u;
|
||||||
char s[STATUS_LEN];
|
char s[STATUS_LEN];
|
||||||
|
@ -220,8 +220,7 @@ static void LinkTable_uninitialised_fill(LinkTable * linktbl)
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} while (u);
|
||||||
while (u);
|
|
||||||
if (CONFIG.log_type & debug) {
|
if (CONFIG.log_type & debug) {
|
||||||
erase_string(stderr, STATUS_LEN, s);
|
erase_string(stderr, STATUS_LEN, s);
|
||||||
fprintf(stderr, "... Done!\n");
|
fprintf(stderr, "... Done!\n");
|
||||||
|
@ -297,7 +296,7 @@ LinkTable *LinkSystem_init(const char *raw_url)
|
||||||
return ROOT_LINK_TBL;
|
return ROOT_LINK_TBL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinkTable_add(LinkTable * linktbl, Link * link)
|
void LinkTable_add(LinkTable *linktbl, Link *link)
|
||||||
{
|
{
|
||||||
linktbl->num++;
|
linktbl->num++;
|
||||||
linktbl->links =
|
linktbl->links =
|
||||||
|
@ -348,10 +347,10 @@ static int linknames_equal(char *linkname, const char *linkname_new)
|
||||||
* check if the link names differ by a single '/'
|
* check if the link names differ by a single '/'
|
||||||
*/
|
*/
|
||||||
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 = strnlen(linkname_new, MAX_FILENAME_LEN);
|
size_t linkname_new_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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -362,15 +361,15 @@ static int linknames_equal(char *linkname, const char *linkname_new)
|
||||||
* Shamelessly copied and pasted from:
|
* Shamelessly copied and pasted from:
|
||||||
* https://github.com/google/gumbo-parser/blob/master/examples/find_links.cc
|
* https://github.com/google/gumbo-parser/blob/master/examples/find_links.cc
|
||||||
*/
|
*/
|
||||||
static void HTML_to_LinkTable(GumboNode * node, LinkTable * linktbl)
|
static void HTML_to_LinkTable(GumboNode *node, LinkTable *linktbl)
|
||||||
{
|
{
|
||||||
if (node->type != GUMBO_NODE_ELEMENT) {
|
if (node->type != GUMBO_NODE_ELEMENT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GumboAttribute *href;
|
GumboAttribute *href;
|
||||||
if (node->v.element.tag == GUMBO_TAG_A &&
|
if (node->v.element.tag == GUMBO_TAG_A &&
|
||||||
(href =
|
(href =
|
||||||
gumbo_get_attribute(&node->v.element.attributes, "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
|
||||||
*/
|
*/
|
||||||
|
@ -385,8 +384,8 @@ static void HTML_to_LinkTable(GumboNode * node, LinkTable * linktbl)
|
||||||
comp_len--;
|
comp_len--;
|
||||||
}
|
}
|
||||||
if (((type == LINK_DIR) || (type == LINK_UNINITIALISED_FILE)) &&
|
if (((type == LINK_DIR) || (type == LINK_UNINITIALISED_FILE)) &&
|
||||||
!linknames_equal(linktbl->links[linktbl->num - 1]->linkname,
|
!linknames_equal(linktbl->links[linktbl->num - 1]->linkname,
|
||||||
href->value)) {
|
href->value)) {
|
||||||
LinkTable_add(linktbl, Link_new(href->value, type));
|
LinkTable_add(linktbl, Link_new(href->value, type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -400,7 +399,7 @@ static void HTML_to_LinkTable(GumboNode * node, LinkTable * linktbl)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Link_set_file_stat(Link * this_link, CURL * curl)
|
void Link_set_file_stat(Link *this_link, CURL *curl)
|
||||||
{
|
{
|
||||||
long http_resp;
|
long http_resp;
|
||||||
CURLcode ret =
|
CURLcode ret =
|
||||||
|
@ -437,7 +436,7 @@ void Link_set_file_stat(Link * this_link, CURL * curl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LinkTable_fill(LinkTable * linktbl)
|
static void LinkTable_fill(LinkTable *linktbl)
|
||||||
{
|
{
|
||||||
Link *head_link = linktbl->links[0];
|
Link *head_link = linktbl->links[0];
|
||||||
for (int i = 1; i < linktbl->num; i++) {
|
for (int i = 1; i < linktbl->num; i++) {
|
||||||
|
@ -460,7 +459,7 @@ static void LinkTable_fill(LinkTable * linktbl)
|
||||||
/**
|
/**
|
||||||
* \brief Reset invalid links in the link table
|
* \brief Reset invalid links in the link table
|
||||||
*/
|
*/
|
||||||
static void LinkTable_invalid_reset(LinkTable * linktbl)
|
static void LinkTable_invalid_reset(LinkTable *linktbl)
|
||||||
{
|
{
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (int i = 0; i < linktbl->num; i++) {
|
for (int i = 0; i < linktbl->num; i++) {
|
||||||
|
@ -473,7 +472,7 @@ static void LinkTable_invalid_reset(LinkTable * linktbl)
|
||||||
lprintf(debug, "%d invalid links\n", j);
|
lprintf(debug, "%d invalid links\n", j);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinkTable_free(LinkTable * linktbl)
|
void LinkTable_free(LinkTable *linktbl)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < linktbl->num; i++) {
|
for (int i = 0; i < linktbl->num; i++) {
|
||||||
FREE(linktbl->links[i]);
|
FREE(linktbl->links[i]);
|
||||||
|
@ -482,7 +481,7 @@ void LinkTable_free(LinkTable * linktbl)
|
||||||
FREE(linktbl);
|
FREE(linktbl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinkTable_print(LinkTable * linktbl)
|
void LinkTable_print(LinkTable *linktbl)
|
||||||
{
|
{
|
||||||
if (CONFIG.log_type & info) {
|
if (CONFIG.log_type & info) {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
@ -498,8 +497,8 @@ void LinkTable_print(LinkTable * linktbl)
|
||||||
this_link->content_length,
|
this_link->content_length,
|
||||||
this_link->linkname, this_link->f_url);
|
this_link->linkname, this_link->f_url);
|
||||||
if ((this_link->type != LINK_FILE)
|
if ((this_link->type != LINK_FILE)
|
||||||
&& (this_link->type != LINK_DIR)
|
&& (this_link->type != LINK_DIR)
|
||||||
&& (this_link->type != LINK_HEAD)) {
|
&& (this_link->type != LINK_HEAD)) {
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -612,7 +611,7 @@ static void LinkTable_disk_delete(const char *dirn)
|
||||||
FREE(metadirn);
|
FREE(metadirn);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LinkTable_disk_save(LinkTable * linktbl, const char *dirn)
|
int LinkTable_disk_save(LinkTable *linktbl, const char *dirn)
|
||||||
{
|
{
|
||||||
char *metadirn = path_append(META_DIR, dirn);
|
char *metadirn = path_append(META_DIR, dirn);
|
||||||
char *path;
|
char *path;
|
||||||
|
@ -728,7 +727,7 @@ LinkTable *path_to_Link_LinkTable_new(const char *path)
|
||||||
return next_table;
|
return next_table;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Link *path_to_Link_recursive(char *path, LinkTable * linktbl)
|
static Link *path_to_Link_recursive(char *path, LinkTable *linktbl)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* skip the leading '/' if it exists
|
* skip the leading '/' if it exists
|
||||||
|
@ -752,7 +751,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, MAX_FILENAME_LEN)) {
|
(path, linktbl->links[i]->linkname, MAX_FILENAME_LEN)) {
|
||||||
/*
|
/*
|
||||||
* We found our link
|
* We found our link
|
||||||
*/
|
*/
|
||||||
|
@ -776,7 +775,7 @@ 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, MAX_FILENAME_LEN)) {
|
(path, linktbl->links[i]->linkname, MAX_FILENAME_LEN)) {
|
||||||
/*
|
/*
|
||||||
* The next sub-directory exists
|
* The next sub-directory exists
|
||||||
*/
|
*/
|
||||||
|
@ -828,7 +827,7 @@ Link *path_to_Link(const char *path)
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransferStruct Link_download_full(Link * link)
|
TransferStruct Link_download_full(Link *link)
|
||||||
{
|
{
|
||||||
char *url = link->f_url;
|
char *url = link->f_url;
|
||||||
CURL *curl = Link_to_curl(link);
|
CURL *curl = Link_to_curl(link);
|
||||||
|
@ -870,8 +869,7 @@ TransferStruct Link_download_full(Link * link)
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
}
|
} while (HTTP_temp_failure(http_resp));
|
||||||
while (HTTP_temp_failure(http_resp));
|
|
||||||
|
|
||||||
ret = curl_easy_getinfo(curl, CURLINFO_FILETIME, &(link->time));
|
ret = curl_easy_getinfo(curl, CURLINFO_FILETIME, &(link->time));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
@ -881,8 +879,10 @@ TransferStruct Link_download_full(Link * link)
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
static CURL *Link_download_curl_setup(Link *link, size_t req_size,
|
||||||
Link_download(Link * link, char *output_buf, size_t req_size, off_t offset)
|
off_t offset,
|
||||||
|
TransferStruct *header,
|
||||||
|
TransferStruct *ts)
|
||||||
{
|
{
|
||||||
if (!link) {
|
if (!link) {
|
||||||
lprintf(fatal, "Invalid supplied\n");
|
lprintf(fatal, "Invalid supplied\n");
|
||||||
|
@ -890,10 +890,36 @@ Link_download(Link * link, char *output_buf, size_t req_size, off_t offset)
|
||||||
|
|
||||||
size_t start = offset;
|
size_t start = offset;
|
||||||
size_t end = start + req_size;
|
size_t end = start + req_size;
|
||||||
|
|
||||||
char range_str[64];
|
char range_str[64];
|
||||||
snprintf(range_str, sizeof(range_str), "%lu-%lu", start, end);
|
snprintf(range_str, sizeof(range_str), "%lu-%lu", start, end);
|
||||||
lprintf(debug, "%s: %s\n", link->linkname, range_str);
|
lprintf(debug, "%s: %s\n", link->linkname, range_str);
|
||||||
|
|
||||||
|
CURL *curl = Link_to_curl(link);
|
||||||
|
CURLcode ret =
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HEADERDATA, (void *) header);
|
||||||
|
if (ret) {
|
||||||
|
lprintf(error, "%s", curl_easy_strerror(ret));
|
||||||
|
}
|
||||||
|
ret = curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) ts);
|
||||||
|
if (ret) {
|
||||||
|
lprintf(error, "%s", curl_easy_strerror(ret));
|
||||||
|
}
|
||||||
|
ret = curl_easy_setopt(curl, CURLOPT_PRIVATE, (void *) ts);
|
||||||
|
if (ret) {
|
||||||
|
lprintf(error, "%s", curl_easy_strerror(ret));
|
||||||
|
}
|
||||||
|
ret = curl_easy_setopt(curl, CURLOPT_RANGE, range_str);
|
||||||
|
if (ret) {
|
||||||
|
lprintf(error, "%s", curl_easy_strerror(ret));
|
||||||
|
}
|
||||||
|
|
||||||
|
return curl;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
Link_download(Link *link, char *output_buf, size_t req_size, off_t offset)
|
||||||
|
{
|
||||||
TransferStruct ts;
|
TransferStruct ts;
|
||||||
ts.size = 0;
|
ts.size = 0;
|
||||||
ts.data = NULL;
|
ts.data = NULL;
|
||||||
|
@ -904,24 +930,8 @@ Link_download(Link * link, char *output_buf, size_t req_size, off_t offset)
|
||||||
header.size = 0;
|
header.size = 0;
|
||||||
header.data = NULL;
|
header.data = NULL;
|
||||||
|
|
||||||
CURL *curl = Link_to_curl(link);
|
CURL *curl = Link_download_curl_setup(link, req_size, offset, &header, &ts);
|
||||||
CURLcode ret =
|
|
||||||
curl_easy_setopt(curl, CURLOPT_HEADERDATA, (void *) &header);
|
|
||||||
if (ret) {
|
|
||||||
lprintf(error, "%s", curl_easy_strerror(ret));
|
|
||||||
}
|
|
||||||
ret = curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &ts);
|
|
||||||
if (ret) {
|
|
||||||
lprintf(error, "%s", curl_easy_strerror(ret));
|
|
||||||
}
|
|
||||||
ret = curl_easy_setopt(curl, CURLOPT_PRIVATE, (void *) &ts);
|
|
||||||
if (ret) {
|
|
||||||
lprintf(error, "%s", curl_easy_strerror(ret));
|
|
||||||
}
|
|
||||||
ret = curl_easy_setopt(curl, CURLOPT_RANGE, range_str);
|
|
||||||
if (ret) {
|
|
||||||
lprintf(error, "%s", curl_easy_strerror(ret));
|
|
||||||
}
|
|
||||||
transfer_blocking(curl);
|
transfer_blocking(curl);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -938,13 +948,13 @@ range requests\n");
|
||||||
FREE(header.data);
|
FREE(header.data);
|
||||||
|
|
||||||
long http_resp;
|
long http_resp;
|
||||||
ret = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_resp);
|
CURLcode ret = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_resp);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
lprintf(error, "%s", curl_easy_strerror(ret));
|
lprintf(error, "%s", curl_easy_strerror(ret));
|
||||||
}
|
}
|
||||||
if (!((http_resp != HTTP_OK) ||
|
if (!((http_resp != HTTP_OK) ||
|
||||||
(http_resp != HTTP_PARTIAL_CONTENT) ||
|
(http_resp != HTTP_PARTIAL_CONTENT) ||
|
||||||
(http_resp != HTTP_RANGE_NOT_SATISFIABLE))) {
|
(http_resp != HTTP_RANGE_NOT_SATISFIABLE))) {
|
||||||
lprintf(warning,
|
lprintf(warning,
|
||||||
"Could not download %s, HTTP %ld\n",
|
"Could not download %s, HTTP %ld\n",
|
||||||
link->f_url, http_resp);
|
link->f_url, http_resp);
|
||||||
|
|
14
src/link.h
14
src/link.h
|
@ -101,7 +101,7 @@ LinkTable *LinkSystem_init(const char *raw_url);
|
||||||
/**
|
/**
|
||||||
* \brief Set the stats of a link, after curl multi handle finished querying
|
* \brief Set the stats of a link, after curl multi handle finished querying
|
||||||
*/
|
*/
|
||||||
void Link_set_file_stat(Link * this_link, CURL * curl);
|
void Link_set_file_stat(Link *this_link, CURL *curl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief create a new LinkTable
|
* \brief create a new LinkTable
|
||||||
|
@ -119,7 +119,7 @@ long path_download(const char *path, char *output_buf, size_t size,
|
||||||
* \brief Download a Link
|
* \brief Download a Link
|
||||||
* \return the number of bytes downloaded
|
* \return the number of bytes downloaded
|
||||||
*/
|
*/
|
||||||
long Link_download(Link * link, char *output_buf, size_t req_size,
|
long Link_download(Link *link, char *output_buf, size_t req_size,
|
||||||
off_t offset);
|
off_t offset);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,7 +135,7 @@ LinkTable *path_to_Link_LinkTable_new(const char *path);
|
||||||
/**
|
/**
|
||||||
* \brief dump a link table to the disk.
|
* \brief dump a link table to the disk.
|
||||||
*/
|
*/
|
||||||
int LinkTable_disk_save(LinkTable * linktbl, const char *dirn);
|
int LinkTable_disk_save(LinkTable *linktbl, const char *dirn);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief load a link table from the disk.
|
* \brief load a link table from the disk.
|
||||||
|
@ -146,7 +146,7 @@ LinkTable *LinkTable_disk_open(const char *dirn);
|
||||||
* \brief Download a link's content to the memory
|
* \brief Download a link's content to the memory
|
||||||
* \warning You MUST free the memory field in TransferStruct after use!
|
* \warning You MUST free the memory field in TransferStruct after use!
|
||||||
*/
|
*/
|
||||||
TransferStruct Link_download_full(Link * head_link);
|
TransferStruct Link_download_full(Link *head_link);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Allocate a LinkTable
|
* \brief Allocate a LinkTable
|
||||||
|
@ -157,15 +157,15 @@ LinkTable *LinkTable_alloc(const char *url);
|
||||||
/**
|
/**
|
||||||
* \brief free a LinkTable
|
* \brief free a LinkTable
|
||||||
*/
|
*/
|
||||||
void LinkTable_free(LinkTable * linktbl);
|
void LinkTable_free(LinkTable *linktbl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief print a LinkTable
|
* \brief print a LinkTable
|
||||||
*/
|
*/
|
||||||
void LinkTable_print(LinkTable * linktbl);
|
void LinkTable_print(LinkTable *linktbl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief add a Link to a LinkTable
|
* \brief add a Link to a LinkTable
|
||||||
*/
|
*/
|
||||||
void LinkTable_add(LinkTable * linktbl, Link * link);
|
void LinkTable_add(LinkTable *linktbl, Link *link);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -42,8 +42,7 @@ log_printf(LogType type, const char *file, const char *func, int line,
|
||||||
|
|
||||||
fprintf(stderr, "%s:%d:", file, line);
|
fprintf(stderr, "%s:%d:", file, line);
|
||||||
|
|
||||||
print_actual_message:
|
print_actual_message: {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%s: ", func);
|
fprintf(stderr, "%s: ", func);
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
|
@ -91,7 +91,7 @@ int main(int argc, char **argv)
|
||||||
*/
|
*/
|
||||||
char *base_url = argv[argc - 2];
|
char *base_url = argv[argc - 2];
|
||||||
if (strncmp(base_url, "http://", 7)
|
if (strncmp(base_url, "http://", 7)
|
||||||
&& strncmp(base_url, "https://", 8)) {
|
&& 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);
|
||||||
|
@ -110,7 +110,7 @@ activate Sonic mode.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fuse_start:
|
fuse_start:
|
||||||
fuse_local_init(fuse_argc, fuse_argv);
|
fuse_local_init(fuse_argc, fuse_argv);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -204,8 +204,8 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc)
|
||||||
{ 0, 0, 0, 0 }
|
{ 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
while ((c =
|
while ((c =
|
||||||
getopt_long(argc, argv, short_opts, long_opts,
|
getopt_long(argc, argv, short_opts, long_opts,
|
||||||
&long_index)) != -1) {
|
&long_index)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'o':
|
case 'o':
|
||||||
add_arg(fuse_argv, fuse_argc, "-o");
|
add_arg(fuse_argv, fuse_argc, "-o");
|
||||||
|
|
|
@ -87,7 +87,7 @@ failed!\n", i);
|
||||||
* https://curl.haxx.se/libcurl/c/threaded-shared-conn.html
|
* https://curl.haxx.se/libcurl/c/threaded-shared-conn.html
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
curl_callback_lock(CURL * handle, curl_lock_data data,
|
curl_callback_lock(CURL *handle, curl_lock_data data,
|
||||||
curl_lock_access access, void *userptr)
|
curl_lock_access access, void *userptr)
|
||||||
{
|
{
|
||||||
(void) access; /* unused */
|
(void) access; /* unused */
|
||||||
|
@ -98,7 +98,7 @@ curl_callback_lock(CURL * handle, curl_lock_data data,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
curl_callback_unlock(CURL * handle, curl_lock_data data, void *userptr)
|
curl_callback_unlock(CURL *handle, curl_lock_data data, void *userptr)
|
||||||
{
|
{
|
||||||
(void) userptr; /* unused */
|
(void) userptr; /* unused */
|
||||||
(void) handle; /* unused */
|
(void) handle; /* unused */
|
||||||
|
@ -112,7 +112,7 @@ curl_callback_unlock(CURL * handle, curl_lock_data data, void *userptr)
|
||||||
* https://curl.haxx.se/libcurl/c/10-at-a-time.html
|
* https://curl.haxx.se/libcurl/c/10-at-a-time.html
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
curl_process_msgs(CURLMsg * curl_msg, int n_running_curl, int n_mesgs)
|
curl_process_msgs(CURLMsg *curl_msg, int n_running_curl, int n_mesgs)
|
||||||
{
|
{
|
||||||
(void) n_running_curl;
|
(void) n_running_curl;
|
||||||
(void) n_mesgs;
|
(void) n_mesgs;
|
||||||
|
@ -316,7 +316,7 @@ void NetworkSystem_init(void)
|
||||||
crypto_lock_init();
|
crypto_lock_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void transfer_blocking(CURL * curl)
|
void transfer_blocking(CURL *curl)
|
||||||
{
|
{
|
||||||
TransferStruct *ts;
|
TransferStruct *ts;
|
||||||
CURLcode ret = curl_easy_getinfo(curl, CURLINFO_PRIVATE, &ts);
|
CURLcode ret = curl_easy_getinfo(curl, CURLINFO_PRIVATE, &ts);
|
||||||
|
@ -343,11 +343,7 @@ void transfer_blocking(CURL * curl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// void transfer_semiblocking(CURL *curl) {
|
void transfer_nonblocking(CURL *curl)
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
void transfer_nonblocking(CURL * curl)
|
|
||||||
{
|
{
|
||||||
lprintf(network_lock_debug,
|
lprintf(network_lock_debug,
|
||||||
"thread %x: locking transfer_lock;\n", pthread_self());
|
"thread %x: locking transfer_lock;\n", pthread_self());
|
||||||
|
|
|
@ -28,10 +28,10 @@ int curl_multi_perform_once(void);
|
||||||
void NetworkSystem_init(void);
|
void NetworkSystem_init(void);
|
||||||
|
|
||||||
/** \brief blocking file transfer */
|
/** \brief blocking file transfer */
|
||||||
void transfer_blocking(CURL * curl);
|
void transfer_blocking(CURL *curl);
|
||||||
|
|
||||||
/** \brief non blocking file transfer */
|
/** \brief non blocking file transfer */
|
||||||
void transfer_nonblocking(CURL * curl);
|
void transfer_nonblocking(CURL *curl);
|
||||||
|
|
||||||
/** \brief callback function for file transfer */
|
/** \brief callback function for file transfer */
|
||||||
size_t
|
size_t
|
||||||
|
|
26
src/sonic.c
26
src/sonic.c
|
@ -252,7 +252,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], MAX_FILENAME_LEN);
|
strncpy(link->linkname, attr[i + 1], MAX_FILENAME_LEN);
|
||||||
linkname_set = 1;
|
linkname_set = 1;
|
||||||
continue;
|
continue;
|
||||||
|
@ -296,7 +296,7 @@ XML_parser_general(void *data, const char *elem, const char **attr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!linkname_set && strnlen(title, MAX_PATH_LEN) > 0 &&
|
if (!linkname_set && strnlen(title, MAX_PATH_LEN) > 0 &&
|
||||||
strnlen(suffix, MAX_PATH_LEN) > 0) {
|
strnlen(suffix, MAX_PATH_LEN) > 0) {
|
||||||
snprintf(link->linkname, MAX_FILENAME_LEN, "%02d - %s.%s",
|
snprintf(link->linkname, MAX_FILENAME_LEN, "%02d - %s.%s",
|
||||||
track, title, suffix);
|
track, title, suffix);
|
||||||
linkname_set = 1;
|
linkname_set = 1;
|
||||||
|
@ -323,8 +323,8 @@ XML_parser_general(void *data, const char *elem, const char **attr)
|
||||||
* \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 LinkTable *sonic_url_to_LinkTable(const char *url,
|
static LinkTable *sonic_url_to_LinkTable(const char *url,
|
||||||
XML_StartElementHandler handler,
|
XML_StartElementHandler handler,
|
||||||
int depth)
|
int depth)
|
||||||
{
|
{
|
||||||
LinkTable *linktbl = LinkTable_alloc(url);
|
LinkTable *linktbl = LinkTable_alloc(url);
|
||||||
linktbl->links[0]->sonic.depth = depth;
|
linktbl->links[0]->sonic.depth = depth;
|
||||||
|
@ -467,25 +467,25 @@ LinkTable *sonic_LinkTable_new_id3(int depth, const char *id)
|
||||||
char *url;
|
char *url;
|
||||||
LinkTable *linktbl = ROOT_LINK_TBL;
|
LinkTable *linktbl = ROOT_LINK_TBL;
|
||||||
switch (depth) {
|
switch (depth) {
|
||||||
/*
|
/*
|
||||||
* Root table
|
* Root table
|
||||||
*/
|
*/
|
||||||
case 0:
|
case 0:
|
||||||
url = sonic_gen_url_first_part("getArtists");
|
url = sonic_gen_url_first_part("getArtists");
|
||||||
linktbl = sonic_url_to_LinkTable(url, XML_parser_id3_root, 0);
|
linktbl = sonic_url_to_LinkTable(url, XML_parser_id3_root, 0);
|
||||||
FREE(url);
|
FREE(url);
|
||||||
break;
|
break;
|
||||||
/*
|
/*
|
||||||
* Album table - get all the albums of an artist
|
* Album table - get all the albums of an artist
|
||||||
*/
|
*/
|
||||||
case 3:
|
case 3:
|
||||||
url = sonic_getArtist_link(id);
|
url = sonic_getArtist_link(id);
|
||||||
linktbl = sonic_url_to_LinkTable(url, XML_parser_general, depth);
|
linktbl = sonic_url_to_LinkTable(url, XML_parser_general, depth);
|
||||||
FREE(url);
|
FREE(url);
|
||||||
break;
|
break;
|
||||||
/*
|
/*
|
||||||
* Song table - get all the songs of an album
|
* Song table - get all the songs of an album
|
||||||
*/
|
*/
|
||||||
case 4:
|
case 4:
|
||||||
url = sonic_getAlbum_link(id);
|
url = sonic_getAlbum_link(id);
|
||||||
linktbl = sonic_url_to_LinkTable(url, XML_parser_general, depth);
|
linktbl = sonic_url_to_LinkTable(url, XML_parser_general, depth);
|
||||||
|
|
|
@ -31,7 +31,7 @@ char *path_append(const char *path, const char *filename)
|
||||||
{
|
{
|
||||||
int needs_separator = 0;
|
int needs_separator = 0;
|
||||||
if ((path[strnlen(path, MAX_PATH_LEN) - 1] != '/')
|
if ((path[strnlen(path, MAX_PATH_LEN) - 1] != '/')
|
||||||
&& (filename[0] != '/')) {
|
&& (filename[0] != '/')) {
|
||||||
needs_separator = 1;
|
needs_separator = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ int64_t round_div(int64_t a, int64_t b)
|
||||||
return (a + (b / 2)) / b;
|
return (a + (b / 2)) / b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PTHREAD_MUTEX_UNLOCK(pthread_mutex_t * x)
|
void PTHREAD_MUTEX_UNLOCK(pthread_mutex_t *x)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
i = pthread_mutex_unlock(x);
|
i = pthread_mutex_unlock(x);
|
||||||
|
@ -62,7 +62,7 @@ void PTHREAD_MUTEX_UNLOCK(pthread_mutex_t * x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PTHREAD_MUTEX_LOCK(pthread_mutex_t * x)
|
void PTHREAD_MUTEX_LOCK(pthread_mutex_t *x)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
i = pthread_mutex_lock(x);
|
i = pthread_mutex_lock(x);
|
||||||
|
@ -86,7 +86,7 @@ void exit_failure(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void erase_string(FILE * file, size_t max_len, char *s)
|
void erase_string(FILE *file, size_t max_len, char *s)
|
||||||
{
|
{
|
||||||
size_t l = strnlen(s, max_len);
|
size_t l = strnlen(s, max_len);
|
||||||
for (size_t k = 0; k < l; k++) {
|
for (size_t k = 0; k < l; k++) {
|
||||||
|
|
|
@ -25,12 +25,12 @@ int64_t round_div(int64_t a, int64_t b);
|
||||||
/**
|
/**
|
||||||
* \brief wrapper for pthread_mutex_lock(), with error handling
|
* \brief wrapper for pthread_mutex_lock(), with error handling
|
||||||
*/
|
*/
|
||||||
void PTHREAD_MUTEX_LOCK(pthread_mutex_t * x);
|
void PTHREAD_MUTEX_LOCK(pthread_mutex_t *x);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief wrapper for pthread_mutex_unlock(), with error handling
|
* \brief wrapper for pthread_mutex_unlock(), with error handling
|
||||||
*/
|
*/
|
||||||
void PTHREAD_MUTEX_UNLOCK(pthread_mutex_t * x);
|
void PTHREAD_MUTEX_UNLOCK(pthread_mutex_t *x);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief wrapper for exit(EXIT_FAILURE), with error handling
|
* \brief wrapper for exit(EXIT_FAILURE), with error handling
|
||||||
|
@ -40,7 +40,7 @@ void exit_failure(void);
|
||||||
/**
|
/**
|
||||||
* \brief erase a string from the terminal
|
* \brief erase a string from the terminal
|
||||||
*/
|
*/
|
||||||
void erase_string(FILE * file, size_t max_len, char *s);
|
void erase_string(FILE *file, size_t max_len, char *s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief generate the salt for authentication string
|
* \brief generate the salt for authentication string
|
||||||
|
|
Loading…
Reference in New Issue