2 libmvfs - metux Virtual Filesystem Library
6 Copyright (C) 2008 Enrico Weigelt, metux IT service <weigelt@metux.de>
7 This code is published under the terms of the GNU Public License 2.0
10 #include "mvfs-internal.h"
18 #include <mvfs/mvfs.h>
20 #include <mvfs/_utils.h>
27 // not very efficient yet, but should work for now
29 MVFS_ARGS
* mvfs_args_alloc()
31 MVFS_ARGS
* args
= calloc(1,sizeof(MVFS_ARGS
));
32 if (!hash_initialise(&(args
->hashtable
), 997U, hash_hash_string
, hash_compare_string
, hash_copy_string
, free
, free
))
34 ERRMSG("hash init failed");
42 const char* mvfs_args_get(MVFS_ARGS
* args
, const char* name
)
47 const char* str
= NULL
;
48 if (hash_retrieve(&(args
->hashtable
), (char*)name
, (void**)&str
))
54 int mvfs_args_set(MVFS_ARGS
* args
, const char* name
, const char* value
)
59 hash_delete(&(args
->hashtable
), (char*)name
);
63 if (!hash_insert(&(args
->hashtable
), strdup(name
), strdup(value
)))
64 ERRMSG("failed for key %s", name
);
69 int mvfs_args_setn(MVFS_ARGS
* args
, const char* name
, const char* value
, int sz
)
74 hash_delete(&(args
->hashtable
), (char*)name
);
78 if (!hash_insert(&(args
->hashtable
), strdup(name
), strndup(value
,sz
)))
79 ERRMSG("failed for key %s", name
);
84 int mvfs_args_free(MVFS_ARGS
* args
)
89 hash_deinitialise(&(args
->hashtable
));
93 MVFS_ARGS
* mvfs_args_from_url(const char* url
)
98 MVFS_URL
* u
= mvfs_url_parse(url
);
99 MVFS_ARGS
* args
= mvfs_args_alloc();
101 mvfs_args_set(args
,"url", url
);
102 mvfs_args_set(args
,"path", u
->pathname
);
103 mvfs_args_set(args
,"host", u
->hostname
);
104 mvfs_args_set(args
,"port", u
->port
);
105 mvfs_args_set(args
,"username", u
->username
);
106 mvfs_args_set(args
,"secret", u
->secret
);
108 if ((!(u
->type
)) || (!(u
->type
[0])))
109 mvfs_args_set(args
,"type", "local");
111 mvfs_args_set(args
,"type", u
->type
);