From 05c45666e59acd7699f27b9485ab809214b09a95 Mon Sep 17 00:00:00 2001 From: Jose Marcial Vieira Bisneto Date: Thu, 24 Nov 2016 07:52:15 -0300 Subject: [PATCH] Added path pointer used to return value in Resolve and ResolveN. --- include/ipfs/namesys/namesys.h | 18 +++++++++++++++-- namesys/base.c | 5 ----- namesys/namesys.c | 35 ++++++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/include/ipfs/namesys/namesys.h b/include/ipfs/namesys/namesys.h index 2ce57d1..4d9581d 100644 --- a/include/ipfs/namesys/namesys.h +++ b/include/ipfs/namesys/namesys.h @@ -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 diff --git a/namesys/base.c b/namesys/base.c index 96b4064..ff4cc03 100644 --- a/namesys/base.c +++ b/namesys/base.c @@ -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; diff --git a/namesys/namesys.c b/namesys/namesys.c index d4240ab..8b95786 100644 --- a/namesys/namesys.c +++ b/namesys/namesys.c @@ -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.