Added path pointer used to return value in Resolve and ResolveN.
This commit is contained in:
parent
7ddba70ada
commit
05c45666e5
3 changed files with 43 additions and 15 deletions
|
@ -11,7 +11,8 @@
|
|||
"Could not resolve name.",
|
||||
"Could not resolve name (recursion limit exceeded).",
|
||||
"expired record",
|
||||
"unrecognized validity type"
|
||||
"unrecognized validity type",
|
||||
"not a valid proquint string"
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -21,7 +22,8 @@
|
|||
ErrResolveFailed,
|
||||
ErrResolveRecursion,
|
||||
ErrExpiredRecord,
|
||||
ErrUnrecognizedValidity
|
||||
ErrUnrecognizedValidity,
|
||||
ErrInvalidProquint
|
||||
} NamesysErrs;
|
||||
|
||||
typedef struct s_resolvers {
|
||||
|
@ -29,6 +31,11 @@
|
|||
int (*func)(char**, char*);
|
||||
} resolvers;
|
||||
|
||||
typedef struct s_resolver {
|
||||
// resolveOnce looks up a name once (without recursion).
|
||||
int (*resolveOnce) (char **, char *);
|
||||
} resolver;
|
||||
|
||||
//TODO ciPrivKey from c-libp2p-crypto
|
||||
typedef void* ciPrivKey;
|
||||
|
||||
|
@ -42,4 +49,11 @@
|
|||
resolvers *resolver;
|
||||
publishers *Publisher;
|
||||
} mpns;
|
||||
|
||||
int resolve (resolver *r, char **p, char *str, int depth, char **prefixes);
|
||||
int Resolve(char **path, char *name);
|
||||
int ResolveN(char **path, char *name, int depth);
|
||||
int resolveOnce (char **path, char *name);
|
||||
int Publish (char *proto, ciPrivKey name, char *value);
|
||||
int PublishWithEOL (char *proto, ciPrivKey name, char *value, time_t eol);
|
||||
#endif //NAMESYS_H
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
#include "ipfs/path/path.h"
|
||||
#include "ipfs/namesys/namesys.h"
|
||||
|
||||
typedef struct s_resolver {
|
||||
// resolveOnce looks up a name once (without recursion).
|
||||
int (*resolveOnce) (char **, char *);
|
||||
} resolver;
|
||||
|
||||
int resolve (resolver *r, char **p, char *str, int depth, char **prefixes)
|
||||
{
|
||||
int err, i;
|
||||
|
|
|
@ -34,18 +34,31 @@ func NewNameSystem(r routing.ValueStore, ds ds.Datastore, cachesize int) NameSys
|
|||
const DefaultResolverCacheTTL = time.Minute;
|
||||
|
||||
// Resolve implements Resolver.
|
||||
int Resolve(char *name)
|
||||
int Resolve(char **path, char *name)
|
||||
{
|
||||
return ResolveN(name, DefaultDepthLimit);
|
||||
return ResolveN(path, name, DefaultDepthLimit);
|
||||
}
|
||||
|
||||
// ResolveN implements Resolver.
|
||||
int ResolveN(char *name, int depth)
|
||||
int ResolveN(char **path, char *name, int depth)
|
||||
{
|
||||
char ipfs_prefix[] = "/ipfs/";
|
||||
char p[500];
|
||||
char *ps[] = {"/ipns/", NULL};
|
||||
int err;
|
||||
resolver r;
|
||||
|
||||
r.resolveOnce = resolveOnce;
|
||||
|
||||
if (memcmp(name, ipfs_prefix, strlen(ipfs_prefix)) == 0) {
|
||||
return ParsePath(name);
|
||||
ParsePath(p, name);
|
||||
*path = malloc(strlen(p) + 1);
|
||||
if (*p) {
|
||||
strcpy(*path, p);
|
||||
} else {
|
||||
err = ErrAllocFailed;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
if (*name == '/') {
|
||||
|
@ -55,13 +68,19 @@ int ResolveN(char *name, int depth)
|
|||
return ErrAllocFailed;
|
||||
}
|
||||
strcpy(str, ipfs_prefix);
|
||||
strcat(str, name+1); // ignore inital / from name, because ipfs_prefix already has it.
|
||||
err = ParsePath(str); // save return value.
|
||||
free (str); // so we can free allocated memory before return.
|
||||
strcat(str, name+1); // ignore inital / from name, because ipfs_prefix already has it.
|
||||
err = ParsePath(p, str); // save return value.
|
||||
free (str); // so we can free allocated memory before return.
|
||||
*path = malloc(strlen(p) + 1);
|
||||
if (*p) {
|
||||
strcpy(*path, p);
|
||||
} else {
|
||||
err = ErrAllocFailed;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
return resolve(ns, name, depth, "/ipns/");
|
||||
return resolve(&r, path, name, depth, ps);
|
||||
}
|
||||
|
||||
// resolveOnce implements resolver.
|
||||
|
|
Loading…
Reference in a new issue