unsigned char key[crypto_shorthash_KEYBYTES];
};
+void hashmap_clear(struct hash_map*);
void *hashmap_find(struct hash_map*,void*,size_t);
void hashmap_free(struct hash_map*);
int hashmap_init(struct hash_map**,size_t);
//}
static struct hash_map *add_queue;
+static struct torrent *current_torrent;
static int add_find_all();
static int add_queue_resize();
}
hashmap_free(add_queue);
- return -1;
+ return 1;
}
static int add_find_all(struct torrent *p) {
log_info(ADD_MESSAGE_ADDING_TORRENT,p->root,p->name);
+ current_torrent = p;
if(ftw(p->root,&ftw_helper,64)<0) {
perror("ftw");
return -1;
}
- return -1;
+ return 1;
}
static int add_queue_resize(size_t new_size) {
if(p!=NULL) {
if((ret = hashmap_insert(new,p->path,strlen(p->path),p))<=0) {
if(ret<0) { return -1; }
+ hashmap_clear(new);
hashmap_free(new);
return add_queue_resize(new_size<<1);
}
}
}
- for(size_t i=0;i<add_queue->size;i++) {
- add_queue->map[i] = NULL;
- }
+ hashmap_clear(add_queue);
old = add_queue;
add_queue = new;
return 1;
}
-static int add_to_queue(const char *path) {
- struct file *to_add;
+static int add_to_queue(struct file *to_add) {
int ret;
- if(file_init(&to_add,path)<0) { return -1; }
while((ret = hashmap_insert(add_queue,path,strlen(path),to_add))<=0) {
if(ret<0) { return -1; }
if(add_queue_resize(add_queue->size<<1)<0) { return -1; }
}
static int ftw_helper(const char *path, const struct stat *st, int typeflag) {
+ struct file *to_add;
+
if(typeflag!=FTW_F) { return 0; }
switch(global_options.file_filter) {
case FILE_FILTER_IGNORE_DOTFILES:
break;
}
- if(add_to_queue(path)<0) { return -1; }
+ if(file_init(&to_add,path)<0) { return -1; }
+
+ if(add_to_queue(to_add)<0) { return -1; }
+
+ if(torrent_add(current_torrent,to_add)<0) { return -1; }
return 0;
}
#include<hashmap.h>
+void hashmap_clear(struct hash_map *p) {
+ for(size_t i=0;i<p->size;i++) {
+ p->map[i] = NULL;
+ }
+}
+
void *hashmap_find(struct hash_map *p, void *key, size_t key_size) {
unsigned char hash[crypto_shorthash_BYTES];
size_t index;
struct torrent **torrents;
+static int torrent_add_file(struct torrent *p, struct file *f);
+
+int torrent_add(struct torrent *p, struct file *f) {
+ if(NULL==p) { return -1; }
+ if(NULL==f) { return -1; }
+
+ if(tree_add(p->file_tree,f)<0) { return -1; }
+ if(torrent_add_file(p,f)<0) { return -1; }
+
+ return 1;
+}
+
+static int torrent_add_file(struct torrent *p, struct file *f) {
+ return -1;
+}
+
void torrent_free(struct torrent *p) {
if(p->root!=NULL) { free(p->root); }
if(p->name!=NULL) { free(p->name); }
+ if(p->files!=NULL) { hashmap_free(p->files); }
if(p->file_tree!=NULL) { tree_free(p->file_tree); }
free(p);
}
(*torrent_p)->root = NULL;
(*torrent_p)->name = NULL;
(*torrent_p)->file_tree = NULL;
+ (*torrent_p)->files = NULL;
(*torrent_p)->root = strdup(root);
if(NULL==(*torrent_p)->root) {
#include<tree.h>
+int tree_add(struct tree *p, struct file *p) {
+ return -1;
+}
+
void tree_free(struct tree *p) {
while(p->file_count>0) {
file_free(p->files[p->file_count-1]);