#include<fs.h>
#include<log.h>
-#include<session.h>
#include<torrent.h>
+#include<session.h>
+
enum file_filters {
FILE_FILTER_IGNORE_DOTFILES,
FILE_FILTER_ALL,
#ifndef __SESSION_H_
#define __SESSION_H_
+#include<hashmap.h>
#include<log.h>
#include<torrent.h>
static int ftw_helper(const char*,const struct stat*,int);
int add() {
+ struct torrent *p;
+
if(hashmap_init(&add_queue,ADD_QUEUE_INITIAL_SIZE)<0) { return -1; }
- for(size_t i=0;i<session.torrent_count;i++) {
- if(add_find_all(session.torrents[i])<0) { return -1; }
+ for(size_t i=0;i<session.torrents.infohashes->size;i++) {
+ p = session.torrents.infohashes->map[i];
+ if(p!=NULL) {
+ if(add_find_all(p)<0) { return -1; }
+ }
}
add_queue_index = 0;
}
static int session_torrent_resize(struct hash_map **map, size_t new_size) {
+ struct hash_map *new, *old;
+
+ if(hashmap_init(&new,new_size)<0) { return -1; }
+
+ flag = 0;
+ if(session.torrents.paths==(*map)) { flag = 1; }
+
+ for(size_t i=0;i<(*map)->size;i++) {
+ p = (*map)->map[i];
+ if(p!=NULL) {
+ if(flag) {
+ if((ret = hashmap_insert(new,p->root,strlen(p->root),p))<=0) {
+ if(ret<0) { goto clean; }
+ goto resize;
+ }
+ } else {
+ if((ret = hashmap_insert(new,p->infohash,crypto_hash_sha256_BYTES,p))<=0) {
+ if(ret<0) { goto clean; }
+ goto resize;
+ }
+ }
+ }
+ }
+
+ hashmap_clear(*map);
+ old = *map;
+ *map = new;
+
+ hashmap_free(old);
+
+ return 1;
+resize:
+ hashmap_clear(new);
+ hashmap_free(new);
+ return session_torrent_resize(map,new_size<<1);
+clean:
+ hashmap_clear(new);
+ hashmap_free(new);
return -1;
}
-DNDEBUG
endif
-check_PROGRAMS = bencode.tests block.tests feed.tests file.tests fs.concat.tests fs.filter.tests hash.tests hashmap.tests meta.tests opt.tests rss.tests torrent.tests tree.tests
+check_PROGRAMS = bencode.tests block.tests feed.tests file.tests fs.concat.tests fs.filter.tests hash.tests hashmap.tests meta.tests opt.tests rss.tests session.tests torrent.tests tree.tests
TESTS = $(check_PROGRAMS)
if ENABLE_MEMCHECK
$(top_srcdir)/src/rss/info.c \
$(top_srcdir)/src/rss/init.c
+session_tests_SOURCES = \
+ $(common_SOURCES) \
+ $(torrent_SOURCES) \
+ session.tests.c
+
torrent_tests_SOURCES = \
$(common_SOURCES) \
$(torrent_SOURCES) \
--- /dev/null
+#include<test_utils.h>
+
+#include<session.h>
+
+int main();
+
+int main() {
+ setup_env();
+
+ clean_env();
+
+ return EXIT_SUCCESS;
+}