diff --git a/Makefile b/Makefile index 80d9ba5..7c81172 100644 --- a/Makefile +++ b/Makefile @@ -63,11 +63,12 @@ doc: doxygen Doxyfile format: - indent -kr -nut src/*.c src/*.h + astyle --style=kr --align-pointer=name src/*.c src/*.h clean: -rm -f src/*.h~ -rm -f src/*.c~ + -rm -f src/*orig -rm -f *.o -rm -f httpdirfs diff --git a/src/cache.c b/src/cache.c index 894125e..8a990e9 100644 --- a/src/cache.c +++ b/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); } if (mkdir - (xdg_cache_home, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) - && (errno != EEXIST)) { + (xdg_cache_home, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) + && (errno != EEXIST)) { lprintf(fatal, "mkdir(): %s\n", strerror(errno)); } char *cache_dir_root = path_append(xdg_cache_home, "/httpdirfs/"); if (mkdir - (cache_dir_root, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) - && (errno != EEXIST)) { + (cache_dir_root, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) + && (errno != EEXIST)) { 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 *full_path = path_append(cache_dir_root, escaped_url); 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)); } FREE(fn); @@ -107,12 +107,12 @@ void CacheSystem_init(const char *path, int url_supplied) * Check if directories exist, if not, create them */ 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)); } 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)); } @@ -123,8 +123,8 @@ void CacheSystem_init(const char *path, int url_supplied) */ sonic_path = path_append(META_DIR, "rest/"); if (mkdir - (sonic_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) - && (errno != EEXIST)) { + (sonic_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) + && (errno != EEXIST)) { lprintf(fatal, "mkdir(): %s\n", strerror(errno)); } FREE(sonic_path); @@ -134,8 +134,8 @@ void CacheSystem_init(const char *path, int url_supplied) */ sonic_path = path_append(DATA_DIR, "rest/"); if (mkdir - (sonic_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) - && (errno != EEXIST)) { + (sonic_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) + && (errno != EEXIST)) { lprintf(fatal, "mkdir(): %s\n", strerror(errno)); } FREE(sonic_path); @@ -148,7 +148,7 @@ void CacheSystem_init(const char *path, int url_supplied) * \brief read a metadata file * \return 0 on success, errno on error. */ -static int Meta_read(Cache * cf) +static int Meta_read(Cache *cf) { FILE *fp = cf->mfp; rewind(fp); @@ -236,7 +236,7 @@ file!\n"); * - -1 on error, * - 0 on success */ -static int Meta_write(Cache * cf) +static int Meta_write(Cache *cf) { FILE *fp = cf->mfp; rewind(fp); @@ -279,7 +279,7 @@ static int Meta_write(Cache * cf) * \details We use sparse creation here * \return exit on failure */ -static void Data_create(Cache * cf) +static void Data_create(Cache *cf) { int fd; int mode; @@ -326,7 +326,7 @@ static long Data_size(const char *fn) * - negative values on error, * - 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) { 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, "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 * - 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) { 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"); } - end: +end: lprintf(cache_lock_debug, "thread %x: unlocking seek_lock;\n", pthread_self()); PTHREAD_MUTEX_UNLOCK(&cf->seek_lock); @@ -499,7 +499,7 @@ static Cache *Cache_alloc() /** * \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)) { lprintf(fatal, "could not destroy seek_lock!\n"); @@ -605,7 +605,7 @@ void Cache_delete(const char *fn) * - 0 on success * - -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); cf->dfp = fopen(datafn, "r+"); @@ -627,7 +627,7 @@ static int Data_open(Cache * cf) * - 0 on success * - -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); cf->mfp = fopen(metafn, "r+"); @@ -647,7 +647,7 @@ static int Meta_open(Cache * cf) * \brief Create a metafile * \return exit on error */ -static void Meta_create(Cache * cf) +static void Meta_create(Cache *cf) { char *metafn = path_append(META_DIR, cf->path); 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; } -void Cache_close(Cache * cf) +void Cache_close(Cache *cf) { lprintf(cache_lock_debug, "thread %x: locking cf_lock;\n", pthread_self()); @@ -909,7 +909,7 @@ void Cache_close(Cache * cf) * \brief Check if a 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; 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 * \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; cf->seg[byte] = i; @@ -952,8 +952,8 @@ which does't make sense\n", pthread_self(), recv); } if ((recv == cf->blksz) || - (cf->next_dl_offset == - (cf->content_length / cf->blksz * cf->blksz))) { + (cf->next_dl_offset == + (cf->content_length / cf->blksz * cf->blksz))) { Data_write(cf, recv_buf, recv, cf->next_dl_offset); Seg_set(cf, cf->next_dl_offset, 1); } else { @@ -976,7 +976,7 @@ error.\n", recv, cf->blksz); } 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) { long send; @@ -1036,7 +1036,7 @@ which does't make sense\n", pthread_self(), recv); * Condition 2: offset is the last segment */ 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); Seg_set(cf, dl_offset, 1); } else { @@ -1053,12 +1053,11 @@ error.\n", recv, cf->blksz); /* * ----------- Download the next segment in background ----------------- */ - bgdl: - { +bgdl: { } 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) - && next_dl_offset < cf->content_length) { + && next_dl_offset < cf->content_length) { /* * Stop the spawning of multiple background pthreads */ diff --git a/src/cache.h b/src/cache.h index 3fe83a6..d781eb0 100644 --- a/src/cache.h +++ b/src/cache.h @@ -118,7 +118,7 @@ Cache *Cache_open(const char *fn); * \brief Close a cache data structure * \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 @@ -146,6 +146,6 @@ void Cache_delete(const char *fn); * \return the length of the segment the cache system managed to obtain. * \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); #endif diff --git a/src/link.c b/src/link.c index 9aa7881..a4fd0a2 100644 --- a/src/link.c +++ b/src/link.c @@ -52,7 +52,7 @@ static Link *Link_new(const char *linkname, LinkType type) return link; } -static CURL *Link_to_curl(Link * link) +static CURL *Link_to_curl(Link *link) { CURL *curl = curl_easy_init(); if (!curl) { @@ -155,7 +155,7 @@ static CURL *Link_to_curl(Link * link) 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); 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 * 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; char s[STATUS_LEN]; @@ -220,8 +220,7 @@ static void LinkTable_uninitialised_fill(LinkTable * linktbl) j++; } } - } - while (u); + } while (u); if (CONFIG.log_type & debug) { erase_string(stderr, STATUS_LEN, s); fprintf(stderr, "... Done!\n"); @@ -297,7 +296,7 @@ LinkTable *LinkSystem_init(const char *raw_url) return ROOT_LINK_TBL; } -void LinkTable_add(LinkTable * linktbl, Link * link) +void LinkTable_add(LinkTable *linktbl, Link *link) { linktbl->num++; 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 '/' */ 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); if ((linkname_new_len - strnlen(linkname, MAX_FILENAME_LEN) == 1) - && (linkname_new[linkname_new_len - 1] == '/')) { + && (linkname_new[linkname_new_len - 1] == '/')) { return 1; } } @@ -362,15 +361,15 @@ static int linknames_equal(char *linkname, const char *linkname_new) * Shamelessly copied and pasted from: * 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) { return; } GumboAttribute *href; 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 */ @@ -385,8 +384,8 @@ static void HTML_to_LinkTable(GumboNode * node, LinkTable * linktbl) comp_len--; } if (((type == LINK_DIR) || (type == LINK_UNINITIALISED_FILE)) && - !linknames_equal(linktbl->links[linktbl->num - 1]->linkname, - href->value)) { + !linknames_equal(linktbl->links[linktbl->num - 1]->linkname, + href->value)) { LinkTable_add(linktbl, Link_new(href->value, type)); } } @@ -400,7 +399,7 @@ static void HTML_to_LinkTable(GumboNode * node, LinkTable * linktbl) return; } -void Link_set_file_stat(Link * this_link, CURL * curl) +void Link_set_file_stat(Link *this_link, CURL *curl) { long http_resp; 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]; 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 */ -static void LinkTable_invalid_reset(LinkTable * linktbl) +static void LinkTable_invalid_reset(LinkTable *linktbl) { int j = 0; 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); } -void LinkTable_free(LinkTable * linktbl) +void LinkTable_free(LinkTable *linktbl) { for (int i = 0; i < linktbl->num; i++) { FREE(linktbl->links[i]); @@ -482,7 +481,7 @@ void LinkTable_free(LinkTable * linktbl) FREE(linktbl); } -void LinkTable_print(LinkTable * linktbl) +void LinkTable_print(LinkTable *linktbl) { if (CONFIG.log_type & info) { int j = 0; @@ -498,8 +497,8 @@ void LinkTable_print(LinkTable * linktbl) this_link->content_length, this_link->linkname, this_link->f_url); if ((this_link->type != LINK_FILE) - && (this_link->type != LINK_DIR) - && (this_link->type != LINK_HEAD)) { + && (this_link->type != LINK_DIR) + && (this_link->type != LINK_HEAD)) { j++; } } @@ -612,7 +611,7 @@ static void LinkTable_disk_delete(const char *dirn) 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 *path; @@ -728,7 +727,7 @@ LinkTable *path_to_Link_LinkTable_new(const char *path) 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 @@ -752,7 +751,7 @@ static Link *path_to_Link_recursive(char *path, LinkTable * linktbl) */ for (int i = 1; i < linktbl->num; i++) { if (!strncmp - (path, linktbl->links[i]->linkname, MAX_FILENAME_LEN)) { + (path, linktbl->links[i]->linkname, MAX_FILENAME_LEN)) { /* * We found our link */ @@ -776,7 +775,7 @@ static Link *path_to_Link_recursive(char *path, LinkTable * linktbl) char *next_path = slash + 1; for (int i = 1; i < linktbl->num; i++) { if (!strncmp - (path, linktbl->links[i]->linkname, MAX_FILENAME_LEN)) { + (path, linktbl->links[i]->linkname, MAX_FILENAME_LEN)) { /* * The next sub-directory exists */ @@ -828,7 +827,7 @@ Link *path_to_Link(const char *path) return link; } -TransferStruct Link_download_full(Link * link) +TransferStruct Link_download_full(Link *link) { char *url = link->f_url; CURL *curl = Link_to_curl(link); @@ -870,8 +869,7 @@ TransferStruct Link_download_full(Link * link) curl_easy_cleanup(curl); return ts; } - } - while (HTTP_temp_failure(http_resp)); + } while (HTTP_temp_failure(http_resp)); ret = curl_easy_getinfo(curl, CURLINFO_FILETIME, &(link->time)); if (ret) { @@ -881,8 +879,10 @@ TransferStruct Link_download_full(Link * link) return ts; } -long -Link_download(Link * link, char *output_buf, size_t req_size, off_t offset) +static CURL *Link_download_curl_setup(Link *link, size_t req_size, + off_t offset, + TransferStruct *header, + TransferStruct *ts) { if (!link) { 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 end = start + req_size; + char range_str[64]; snprintf(range_str, sizeof(range_str), "%lu-%lu", start, end); 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; ts.size = 0; 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.data = NULL; - 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)); - } + CURL *curl = Link_download_curl_setup(link, req_size, offset, &header, &ts); + transfer_blocking(curl); /* @@ -938,13 +948,13 @@ range requests\n"); FREE(header.data); 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) { lprintf(error, "%s", curl_easy_strerror(ret)); } if (!((http_resp != HTTP_OK) || - (http_resp != HTTP_PARTIAL_CONTENT) || - (http_resp != HTTP_RANGE_NOT_SATISFIABLE))) { + (http_resp != HTTP_PARTIAL_CONTENT) || + (http_resp != HTTP_RANGE_NOT_SATISFIABLE))) { lprintf(warning, "Could not download %s, HTTP %ld\n", link->f_url, http_resp); diff --git a/src/link.h b/src/link.h index 1773af8..51716de 100644 --- a/src/link.h +++ b/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 */ -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 @@ -119,7 +119,7 @@ long path_download(const char *path, char *output_buf, size_t size, * \brief Download a Link * \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); /** @@ -135,7 +135,7 @@ LinkTable *path_to_Link_LinkTable_new(const char *path); /** * \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. @@ -146,7 +146,7 @@ LinkTable *LinkTable_disk_open(const char *dirn); * \brief Download a link's content to the memory * \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 @@ -157,15 +157,15 @@ LinkTable *LinkTable_alloc(const char *url); /** * \brief free a LinkTable */ -void LinkTable_free(LinkTable * linktbl); +void LinkTable_free(LinkTable *linktbl); /** * \brief print a LinkTable */ -void LinkTable_print(LinkTable * linktbl); +void LinkTable_print(LinkTable *linktbl); /** * \brief add a Link to a LinkTable */ -void LinkTable_add(LinkTable * linktbl, Link * link); +void LinkTable_add(LinkTable *linktbl, Link *link); #endif diff --git a/src/log.c b/src/log.c index 1a46f0f..bb03ddb 100644 --- a/src/log.c +++ b/src/log.c @@ -42,8 +42,7 @@ log_printf(LogType type, const char *file, const char *func, int line, fprintf(stderr, "%s:%d:", file, line); - print_actual_message: - { +print_actual_message: { } fprintf(stderr, "%s: ", func); va_list args; diff --git a/src/main.c b/src/main.c index 6ea8edc..17b9f94 100644 --- a/src/main.c +++ b/src/main.c @@ -91,7 +91,7 @@ int main(int argc, char **argv) */ char *base_url = argv[argc - 2]; 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"); print_help(argv[0], 0); exit(EXIT_FAILURE); @@ -110,7 +110,7 @@ activate Sonic mode.\n"); } } - fuse_start: +fuse_start: fuse_local_init(fuse_argc, fuse_argv); return 0; @@ -204,8 +204,8 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc) { 0, 0, 0, 0 } }; while ((c = - getopt_long(argc, argv, short_opts, long_opts, - &long_index)) != -1) { + getopt_long(argc, argv, short_opts, long_opts, + &long_index)) != -1) { switch (c) { case 'o': add_arg(fuse_argv, fuse_argc, "-o"); diff --git a/src/network.c b/src/network.c index c2090a3..6e651fe 100644 --- a/src/network.c +++ b/src/network.c @@ -87,7 +87,7 @@ failed!\n", i); * https://curl.haxx.se/libcurl/c/threaded-shared-conn.html */ 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) { (void) access; /* unused */ @@ -98,7 +98,7 @@ curl_callback_lock(CURL * handle, curl_lock_data data, } 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) 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 */ 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_mesgs; @@ -316,7 +316,7 @@ void NetworkSystem_init(void) crypto_lock_init(); } -void transfer_blocking(CURL * curl) +void transfer_blocking(CURL *curl) { TransferStruct *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, "thread %x: locking transfer_lock;\n", pthread_self()); diff --git a/src/network.h b/src/network.h index 15c2dc5..3c96729 100644 --- a/src/network.h +++ b/src/network.h @@ -28,10 +28,10 @@ int curl_multi_perform_once(void); void NetworkSystem_init(void); /** \brief blocking file transfer */ -void transfer_blocking(CURL * curl); +void transfer_blocking(CURL *curl); /** \brief non blocking file transfer */ -void transfer_nonblocking(CURL * curl); +void transfer_nonblocking(CURL *curl); /** \brief callback function for file transfer */ size_t diff --git a/src/sonic.c b/src/sonic.c index 0995022..fa21785 100644 --- a/src/sonic.c +++ b/src/sonic.c @@ -252,7 +252,7 @@ XML_parser_general(void *data, const char *elem, const char **attr) */ if (!linkname_set) { if (!strcmp("title", attr[i]) - || !strcmp("name", attr[i])) { + || !strcmp("name", attr[i])) { strncpy(link->linkname, attr[i + 1], MAX_FILENAME_LEN); linkname_set = 1; 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 && - strnlen(suffix, MAX_PATH_LEN) > 0) { + strnlen(suffix, MAX_PATH_LEN) > 0) { snprintf(link->linkname, MAX_FILENAME_LEN, "%02d - %s.%s", track, title, suffix); 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 */ static LinkTable *sonic_url_to_LinkTable(const char *url, - XML_StartElementHandler handler, - int depth) + XML_StartElementHandler handler, + int depth) { LinkTable *linktbl = LinkTable_alloc(url); linktbl->links[0]->sonic.depth = depth; @@ -467,25 +467,25 @@ LinkTable *sonic_LinkTable_new_id3(int depth, const char *id) char *url; LinkTable *linktbl = ROOT_LINK_TBL; switch (depth) { - /* - * Root table - */ + /* + * Root table + */ case 0: url = sonic_gen_url_first_part("getArtists"); linktbl = sonic_url_to_LinkTable(url, XML_parser_id3_root, 0); FREE(url); break; - /* - * Album table - get all the albums of an artist - */ + /* + * Album table - get all the albums of an artist + */ case 3: url = sonic_getArtist_link(id); linktbl = sonic_url_to_LinkTable(url, XML_parser_general, depth); FREE(url); break; - /* - * Song table - get all the songs of an album - */ + /* + * Song table - get all the songs of an album + */ case 4: url = sonic_getAlbum_link(id); linktbl = sonic_url_to_LinkTable(url, XML_parser_general, depth); diff --git a/src/util.c b/src/util.c index 2acb11f..bd2ea1b 100644 --- a/src/util.c +++ b/src/util.c @@ -31,7 +31,7 @@ char *path_append(const char *path, const char *filename) { int needs_separator = 0; if ((path[strnlen(path, MAX_PATH_LEN) - 1] != '/') - && (filename[0] != '/')) { + && (filename[0] != '/')) { needs_separator = 1; } @@ -52,7 +52,7 @@ int64_t round_div(int64_t a, int64_t b) return (a + (b / 2)) / b; } -void PTHREAD_MUTEX_UNLOCK(pthread_mutex_t * x) +void PTHREAD_MUTEX_UNLOCK(pthread_mutex_t *x) { int i; 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; i = pthread_mutex_lock(x); @@ -86,7 +86,7 @@ void exit_failure(void) 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); for (size_t k = 0; k < l; k++) { diff --git a/src/util.h b/src/util.h index 9361ac4..5010de4 100644 --- a/src/util.h +++ b/src/util.h @@ -25,12 +25,12 @@ int64_t round_div(int64_t a, int64_t b); /** * \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 */ -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 @@ -40,7 +40,7 @@ void exit_failure(void); /** * \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