1 |
/* Support for opening stores named in URL syntax. |
/* Support for opening stores named in URL syntax. |
2 |
|
|
3 |
Copyright (C) 2001 Free Software Foundation, Inc. |
Copyright (C) 2001,02 Free Software Foundation, Inc. |
4 |
|
|
5 |
This file is part of the GNU Hurd. |
This file is part of the GNU Hurd. |
6 |
|
|
22 |
#include <string.h> |
#include <string.h> |
23 |
#include <stdlib.h> |
#include <stdlib.h> |
24 |
|
|
|
static const struct store_class * |
|
|
find_url_class (const char *name, const struct store_class *const *classes) |
|
|
{ |
|
|
const struct store_class *const *cl; |
|
|
const char *clname_end = strchr (name, ':'); |
|
|
|
|
|
if (clname_end == name || clname_end == 0) |
|
|
return 0; |
|
|
|
|
|
for (cl = classes ?: store_std_classes; *cl; cl++) |
|
|
if (strlen ((*cl)->name) == (clname_end - name) |
|
|
&& strncmp (name, (*cl)->name, (clname_end - name)) == 0) |
|
|
return *cl; |
|
|
|
|
|
return 0; |
|
|
} |
|
25 |
|
|
26 |
/* Similar to store_typed_open, but NAME must be in URL format, |
/* Similar to store_typed_open, but NAME must be in URL format, |
27 |
i.e. a class name followed by a ':' and any type-specific name. |
i.e. a class name followed by a ':' and any type-specific name. |
33 |
const struct store_class *const *classes, |
const struct store_class *const *classes, |
34 |
struct store **store) |
struct store **store) |
35 |
{ |
{ |
36 |
const struct store_class *cl = find_url_class (name, classes); |
if (name == 0 || name[0] == ':' || strchr (name, ':') == 0) |
|
|
|
|
if (cl == 0) |
|
37 |
return EINVAL; |
return EINVAL; |
38 |
|
|
39 |
if (! cl->open) |
return store_typed_open (name, flags, classes, store); |
|
/* CL cannot be opened. */ |
|
|
return EOPNOTSUPP; |
|
|
|
|
|
return (*cl->open) (name, flags, classes, store); |
|
40 |
} |
} |
41 |
|
|
42 |
static error_t |
error_t |
43 |
url_decode (struct store_enc *enc, const struct store_class *const *classes, |
store_url_decode (struct store_enc *enc, |
44 |
struct store **store) |
const struct store_class *const *classes, |
45 |
|
struct store **store) |
46 |
{ |
{ |
47 |
const struct store_class *cl; |
const struct store_class *cl; |
48 |
|
|
62 |
return err; |
return err; |
63 |
|
|
64 |
/* Find the class matching this name. */ |
/* Find the class matching this name. */ |
65 |
cl = find_url_class (dummy.name, classes); |
cl = store_find_class (dummy.name, strchr (dummy.name, ':'), classes); |
66 |
|
# pragma weak store_module_find_class |
67 |
|
if (cl == 0 && store_module_find_class) |
68 |
|
err = store_module_find_class (dummy.name, strchr (dummy.name, ':'), |
69 |
|
&cl); |
70 |
free (dummy.name); |
free (dummy.name); |
71 |
free (dummy.misc); |
free (dummy.misc); |
72 |
|
|
87 |
{ |
{ |
88 |
STORAGE_NETWORK, "url", |
STORAGE_NETWORK, "url", |
89 |
open: store_url_open, |
open: store_url_open, |
90 |
decode: url_decode |
decode: store_url_decode |
91 |
}; |
}; |
92 |
|
STORE_STD_CLASS (url_open); |