};
void hashmap_clear(struct hash_map*);
-void *hashmap_find(struct hash_map*,void*,size_t);
+void *hashmap_find(struct hash_map*,const void*,size_t);
void hashmap_free(struct hash_map*);
int hashmap_init(struct hash_map**,size_t);
int hashmap_insert(struct hash_map*,const void*,size_t,void*);
-void *hashmap_remove(struct hash_map*,void*,size_t);
+void *hashmap_remove(struct hash_map*,const void*,size_t);
#endif
struct hash_map *files;
};
+int torrent_add(struct torrent*,struct file*);
void torrent_free(struct torrent*);
int torrent_init(struct torrent**,const char*,const char*);
size_t directory_count;
};
+int tree_add(struct tree*,struct file*);
void tree_free(struct tree*);
int tree_init(struct tree**);
}
static int add_to_queue(struct file *to_add) {
+ struct file *p;
int ret;
+ size_t len;
+
+ len = strlen(to_add->path);
+ p = hashmap_find(add_queue,to_add->path,len);
+ if(p!=NULL) { return 0; }
- while((ret = hashmap_insert(add_queue,path,strlen(path),to_add))<=0) {
+ while((ret = hashmap_insert(add_queue,to_add->path,len,to_add))<=0) {
if(ret<0) { return -1; }
if(add_queue_resize(add_queue->size<<1)<0) { return -1; }
}
}
}
-void *hashmap_find(struct hash_map *p, void *key, size_t key_size) {
+void *hashmap_find(struct hash_map *p, const void *key, size_t key_size) {
unsigned char hash[crypto_shorthash_BYTES];
size_t index;
return 1;
}
-void *hashmap_remove(struct hash_map *p, void *key, size_t key_size) {
+void *hashmap_remove(struct hash_map *p, const void *key, size_t key_size) {
unsigned char hash[crypto_shorthash_BYTES];
size_t index;
void *removed;
#include<tree.h>
-int tree_add(struct tree *p, struct file *p) {
+static int tree_add_directory(struct tree*,const char*);
+static int tree_add_file(struct tree*,struct file*);
+
+int tree_add(struct tree *root, struct file *p) {
+ char *str, *p, *prev;
+ struct tree *tree;
+ int index;
+
+ if(NULL==root) { return -1; }
+ tree = root;
+
+ str = strdup(p->path);
+ if(NULL==str) { return -1; }
+
+ prev = str;
+ p = strtok(str,"/");
+ while(p) {
+ if((index = tree_find_directory(tree,p))<0) {
+ if((index = tree_add_directory(p))<0) { goto clean; }
+ }
+ tree = tree->directories[index];
+
+ prev = p;
+ p = strtok(NULL,"/");
+ }
+
+ if(tree_add_file(tree,prev)<0) { goto clean; }
+
+ free(str);
+
+ return 1;
+ clean:
+ free(str);
+ return -1;
+}
+
+static int tree_add_directory(struct tree *p, const char *dirname) {
+ return -1;
+}
+
+static int tree_add_file(struct tree *tree, struct file *p) {
+ return -1;
+}
+
+int tree_find_directory(struct tree *p, const char *dirname) {
+ return -1;
+}
+
+int tree_find_entry(struct tree *p, const char *filename) {
return -1;
}