namesys/path: Renamed the function names to match the rest of the project.

yamux
Jose Marcial Vieira Bisneto 2016-12-05 08:55:17 -03:00
parent bf9ddfd6f6
commit 496ae3ec6c
11 changed files with 147 additions and 147 deletions

View File

@ -65,7 +65,7 @@
typedef struct s_mpns {
resolvers *resolver;
publishers *Publisher;
publishers *publisher;
} mpns;
typedef struct s_tlds {
@ -73,30 +73,30 @@
int condition;
} tlds;
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);
int ipfs_namesys_resolve (resolver *r, char **p, char *str, int depth, char **prefixes);
int ipfs_namesys_resolve(char **path, char *name);
int ipfs_namesys_resolve_n(char **path, char *name, int depth);
int ipfs_namesys_resolve_once (char **path, char *name);
int ipfs_namesys_publish (char *proto, ciPrivKey name, char *value);
int ipfs_namesys_publish_with_eol (char *proto, ciPrivKey name, char *value, time_t eol);
int ProquintIsProquint(char *str);
char *ProquintEncode(char *buf, int size);
char *ProquintDecode(char *str);
int ProquintResolveOnce (char **p, char *name);
int ipfs_proquint_is_proquint(char *str);
char *ipfs_proquint_encode(char *buf, int size);
char *ipfs_proquint_decode(char *str);
int ipfs_proquint_resolve_once (char **p, char *name);
int domainMatchString (char *d);
int IsICANNTLD(char *s);
int IsExtendedTLD (char *s);
int IsTLD (char *s);
int IsDomain (char *s);
int ipfs_isdomain_match_string (char *d);
int ipfs_isdomain_is_icann_tld(char *s);
int ipfs_isdomain_is_extended_tld (char *s);
int ipfs_isdomain_is_tld (char *s);
int ipfs_isdomain_is_domain (char *s);
typedef struct s_DNSResolver {
// TODO
} DNSResolver;
int DNSResolverResolveOnce (DNSResolver *r, char **path, char *name);
int workDomain (int output, DNSResolver *r, char *name);
int parseEntry (char **Path, char *txt);
int tryParseDnsLink (char **Path, char *txt);
int ipfs_dns_resolver_resolve_once (DNSResolver *r, char **path, char *name);
int ipfs_dns_work_domain (int output, DNSResolver *r, char *name);
int ipfs_dns_parse_entry (char **Path, char *txt);
int ipfs_dns_try_parse_dns_link (char **Path, char *txt);
#endif //NAMESYS_H

View File

@ -24,15 +24,15 @@
ErrNoLinkFmt
} PathErrs;
char* PathFromCid (struct Cid *c);
char** SplitN (char *p, char *delim, int n);
char** Segments (char *p);
int SegmentsLength (char **s);
void FreeSegments (char ***s);
int IsJustAKey (char *p);
int PopLastSegment (char **str, char *p);
char *PathFromSegments(char *prefix, char **seg);
int ParseCidToPath (char *dst, char *txt);
int ParsePath (char *dst, char *txt);
int PathIsValid (char *p);
char* ipfs_path_from_cid (struct Cid *c);
char** ipfs_path_split_n (char *p, char *delim, int n);
char** ipfs_path_split_segments (char *p);
int ipfs_path_segments_length (char **s);
void ipfs_path_free_segments (char ***s);
int ipfs_path_is_just_a_key (char *p);
int ipfs_path_pop_last_segment (char **str, char *p);
char *ipfs_path_from_segments(char *prefix, char **seg);
int ipfs_path_parse_from_cid (char *dst, char *txt);
int ipfs_path_parse (char *dst, char *txt);
int ipfs_path_is_valid (char *p);
#endif // IPFS_PATH_H

View File

@ -4,7 +4,7 @@
#include "ipfs/path/path.h"
#include "ipfs/namesys/namesys.h"
int resolve (resolver *r, char **p, char *str, int depth, char **prefixes)
int ipfs_namesys_base_resolve (resolver *r, char **p, char *str, int depth, char **prefixes)
{
int err, i;
char ipfs_prefix[] = "/ipfs/";
@ -26,7 +26,7 @@ int resolve (resolver *r, char **p, char *str, int depth, char **prefixes)
}
for (i = 0 ; prefixes[i] ; i++) {
if (memcmp(*p, prefixes[i], strlen(prefixes[i])) == 0) {
if (SegmentsLength(prefixes) == 1) {
if (ipfs_path_segments_length(prefixes) == 1) {
str += strlen(prefixes[i]);
}
break;

View File

@ -48,18 +48,18 @@ type lookupRes struct {
// resolveOnce implements resolver.
// TXT records for a given domain name should contain a b58
// encoded multihash.
int DNSResolverResolveOnce (char **path, char *name)
int ipfs_dns_resolver_resolve_once (char **path, char *name)
{
char **segments, *domain, *dnslink, buf[500], dlprefix[] = "_dnslink.";
int p1[2], p2[2], r, c=2;
struct pollfd event[2], *e;
segments = SplitN(name, "/", 2);
segments = ipfs_path_split_n(name, "/", 2);
domain = segments[0];
*path = NULL;
if (!IsDomain(domain)) {
if (!ipfs_isdomain_is_domain(domain)) {
return ErrInvalidDomain;
}
//log.Infof("DNSResolver resolving %s", domain);
@ -74,7 +74,7 @@ int DNSResolverResolveOnce (char **path, char *name)
return ErrPipe;
case 0: // child
close(p1[STDIN_FILENO]); // we don't need to read at child process.
return workDomain (p1[STDOUT_FILENO], r, domain);
return ipfs_dns_work_domain (p1[STDOUT_FILENO], r, domain);
}
close(p1[STDOUT_FILENO]); // we don't need to write at main process.
r = fork();
@ -91,7 +91,7 @@ int DNSResolverResolveOnce (char **path, char *name)
strcpy (dnslink, dlprefix);
strcat (dnslink, domain);
return workDomain (p2[STDOUT_FILENO], r, dnslink);
return ipfs_dns_work_domain (p2[STDOUT_FILENO], r, dnslink);
}
close(p2[STDOUT_FILENO]); // we don't need to write at main process.
@ -137,23 +137,23 @@ int DNSResolverResolveOnce (char **path, char *name)
return ErrResolveFailed;
}
if (SegmentsLength (segments) > 1) {
if (ipfs_path_segments_length (segments) > 1) {
name = *path + strlen(*path) - 1;
while (*name == '/') {
*name-- = '\0';
}
name = *path;
*path = PathFromSegments (name, segments+1);
*path = ipfs_path_from_segments (name, segments+1);
free (name);
if (!*path) {
return ErrResolveFailed;
}
}
FreeSegments (&segments);
ipfs_path_free_segments (&segments);
return 0;
}
int workDomain (int output, DNSResolver *r, char *name)
int ipfs_dns_work_domain (int output, DNSResolver *r, char *name)
{
char **txt, *path;
int i, err = r->lookupTXT(&txt, name);
@ -163,7 +163,7 @@ int workDomain (int output, DNSResolver *r, char *name)
}
for (i = 0 ; txt[i] ; i++) {
err = parseEntry (&path, txt[i]);
err = ipfs_dns_parse_entry (&path, txt[i]);
if (!err) {
err = (write (output, path, strlen(path)) != strlen(path));
free (path);
@ -176,12 +176,12 @@ int workDomain (int output, DNSResolver *r, char *name)
return ErrResolveFailed;
}
int parseEntry (char **path, char *txt)
int ipfs_dns_parse_entry (char **path, char *txt)
{
char buf[500];
int err;
err = ParseCidToPath(buf, txt); // bare IPFS multihashes
err = ipfs_path_parse_from_cid(buf, txt); // bare IPFS multihashes
if (! err) {
*path = malloc(strlen(buf) + 1);
if (!*path) {
@ -190,16 +190,16 @@ int parseEntry (char **path, char *txt)
strcpy(*path, buf);
return 0;
}
return tryParseDnsLink(path, txt);
return ipfs_dns_try_parse_dns_link(path, txt);
}
int tryParseDnsLink(char **path, char *txt)
int ipfs_dns_try_parse_dns_link(char **path, char *txt)
{
char **parts = SplitN(txt, "=", 2), buf[500];
char **parts = ipfs_path_split_n(txt, "=", 2), buf[500];
int err;
if (SegmentsLength(parts) == 2 && strcmp(parts[0], "dnslink")==0) {
err = ParsePath(buf, parts[1]);
if (ipfs_path_segments_length(parts) == 2 && strcmp(parts[0], "dnslink")==0) {
err = ipfs_path_parse(buf, parts[1]);
if (err == 0) {
*parts = malloc(strlen(buf) + 1);
if (! *parts) {

View File

@ -25,7 +25,7 @@ int main(int argc, char **argv)
};
for (i = 0 ; chk[i].str ; i++) {
if (IsDomain (chk[i].str) != chk[i].condition) {
if (ipfs_isdomain_is_domain (chk[i].str) != chk[i].condition) {
printf ("Misclassification: %s should be %d\n", chk[i].str, chk[i].condition);
}
}

View File

@ -4,7 +4,7 @@
#include "ipfs/namesys/namesys.h"
#include "ipfs/namesys/isdomain.h"
void ToUpper(char *dst, char *src)
void ipfs_isdomain_to_upper(char *dst, char *src)
{
while(*src) {
*dst++ = toupper(*src++);
@ -12,7 +12,7 @@ void ToUpper(char *dst, char *src)
*dst = '\0';
}
int HasSuffix (char *s, char *suf)
int ipfs_isdomain_has_suffix (char *s, char *suf)
{
char *p;
@ -20,11 +20,11 @@ int HasSuffix (char *s, char *suf)
return strcmp(p, suf) == 0;
}
int IsAtArray(tlds *a, char *s)
int ipfs_isdomain_is_at_array(tlds *a, char *s)
{
char str[strlen(s)+1];
ToUpper(str, s);
ipfs_isdomain_to_upper(str, s);
while(a->str) {
if (strcmp(a->str, str) == 0) {
return a->condition;
@ -34,11 +34,11 @@ int IsAtArray(tlds *a, char *s)
return 0;
}
int domainMatchString (char *d)
int ipfs_isdomain_match_string (char *d)
{
char str[strlen(d)+1], *p = str, *l;
ToUpper(str, d);
ipfs_isdomain_to_upper(str, d);
// l point to last two chars.
l = p + strlen(p) - 2;
@ -64,31 +64,31 @@ int domainMatchString (char *d)
return 1; // valid
}
// IsICANNTLD returns whether the given string is a TLD (Top Level Domain),
// ipfs_isdomain_is_icann_tld returns whether the given string is a TLD (Top Level Domain),
// according to ICANN. Well, really according to the TLDs listed in this
// package.
int IsICANNTLD(char *s)
int ipfs_isdomain_is_icann_tld(char *s)
{
return IsAtArray (TLDs, s);
return ipfs_isdomain_is_at_array (TLDs, s);
}
// IsExtendedTLD returns whether the given string is a TLD (Top Level Domain),
// ipfs_isdomain_is_extended_tld returns whether the given string is a TLD (Top Level Domain),
// extended with a few other "TLDs", .bit, .onion
int IsExtendedTLD (char *s)
int ipfs_isdomain_is_extended_tld (char *s)
{
return IsAtArray (ExtendedTLDs, s);
return ipfs_isdomain_is_at_array (ExtendedTLDs, s);
}
// IsTLD returns whether the given string is a TLD (according to ICANN, or
// ipfs_isdomain_is_tld returns whether the given string is a TLD (according to ICANN, or
// in the set of ExtendedTLDs listed in this package.
int IsTLD (char *s)
int ipfs_isdomain_is_tld (char *s)
{
return IsICANNTLD (s) || IsExtendedTLD(s);
return ipfs_isdomain_is_icann_tld (s) || ipfs_isdomain_is_extended_tld(s);
}
// IsDomain returns whether given string is a domain.
// ipfs_isdomain_is_domain returns whether given string is a domain.
// It first checks the TLD, and then uses a regular expression.
int IsDomain (char *s)
int ipfs_isdomain_is_domain (char *s)
{
char str[strlen(s)];
char *tld;
@ -96,7 +96,7 @@ int IsDomain (char *s)
strcpy(str, s);
s = str; // work with local copy.
if (HasSuffix (s, ".")) {
if (ipfs_isdomain_has_suffix (s, ".")) {
s[strlen(s) - 1] = '\0';
}
@ -108,9 +108,9 @@ int IsDomain (char *s)
tld++; // ignore last dot
if (!IsTLD (tld)) {
if (!ipfs_isdomain_is_tld (tld)) {
return 0;
}
return domainMatchString(s);
return ipfs_isdomain_match_string(s);
}

View File

@ -34,14 +34,14 @@ func NewNameSystem(r routing.ValueStore, ds ds.Datastore, cachesize int) NameSys
const DefaultResolverCacheTTL = time.Minute;
// Resolve implements Resolver.
int Resolve(char **path, char *name)
// ipfs_namesys_resolve implements Resolver.
int ipfs_namesys_resolve(char **path, char *name)
{
return ResolveN(path, name, DefaultDepthLimit);
return ipfs_namesys_resolve_n(path, name, DefaultDepthLimit);
}
// ResolveN implements Resolver.
int ResolveN(char **path, char *name, int depth)
// ipfs_namesys_resolve_n implements Resolver.
int ipfs_namesys_resolve_n(char **path, char *name, int depth)
{
char ipfs_prefix[] = "/ipfs/";
char p[500];
@ -49,10 +49,10 @@ int ResolveN(char **path, char *name, int depth)
int err;
resolver r;
r.resolveOnce = resolveOnce;
r.resolveOnce = ipfs_namesys_resolve_once;
if (memcmp(name, ipfs_prefix, strlen(ipfs_prefix)) == 0) {
ParsePath(p, name);
ipfs_path_parse(p, name);
*path = malloc(strlen(p) + 1);
if (*p) {
strcpy(*path, p);
@ -70,7 +70,7 @@ int ResolveN(char **path, char *name, int depth)
}
strcpy(str, ipfs_prefix);
strcat(str, name+1); // ignore inital / from name, because ipfs_prefix already has it.
err = ParsePath(p, str); // save return value.
err = ipfs_path_parse(p, str); // save return value.
free (str); // so we can free allocated memory before return.
*path = malloc(strlen(p) + 1);
if (*p) {
@ -81,11 +81,11 @@ int ResolveN(char **path, char *name, int depth)
return err;
}
return resolve(&r, path, name, depth, ps);
return ipfs_namesys_resolve(&r, path, name, depth, ps);
}
// resolveOnce implements resolver.
int resolveOnce (char **path, char *name)
// ipfs_namesys_resolve_once implements resolver.
int ipfs_namesys_resolve_once (char **path, char *name)
{
char ipns_prefix[] = "/ipns/";
char *ptr = NULL;
@ -103,13 +103,13 @@ int resolveOnce (char **path, char *name)
}
strcpy(ptr, ipns_prefix);
strcat(ptr, name);
segs = Segments(ptr);
segs = ipfs_path_split_segments(ptr);
free (ptr);
} else {
segs = Segments(name);
segs = ipfs_path_split_segments(name);
}
if (!segs || SegmentsLength(segs) < 2) {
if (!segs || ipfs_path_segments_length(segs) < 2) {
//log.Warningf("Invalid name syntax for %s", name);
return ErrResolveFailed;
}
@ -119,8 +119,8 @@ int resolveOnce (char **path, char *name)
//log.Debugf("Attempting to resolve %s with %s", segments[1], ns[i]->resolver->protocol);
err = ns[i]->resolver->func(&p, segs[1]);
if (!err) {
if (SegmentsLength(segs) > 2) {
*path = PathFromSegments(p, segs+2);
if (ipfs_path_segments_length(segs) > 2) {
*path = ipfs_path_from_segments(p, segs+2);
} else {
*path = p;
}
@ -131,8 +131,8 @@ int resolveOnce (char **path, char *name)
return ErrResolveFailed;
}
// Publish implements Publisher
int Publish (char *proto, ciPrivKey name, char *value)
// ipfs_namesys_publish implements Publisher
int ipfs_namesys_publish (char *proto, ciPrivKey name, char *value)
{
int i;
@ -144,7 +144,7 @@ int Publish (char *proto, ciPrivKey name, char *value)
return ErrPublishFailed;
}
int PublishWithEOL (char *proto, ciPrivKey name, char *value, time_t eol)
int ipfs_namesys_publish_with_eol (char *proto, ciPrivKey name, char *value, time_t eol)
{
int i;

View File

@ -44,7 +44,7 @@ static inline int vowsd(char c)
* @return {bool} Whether or not it qualifies.
* @return {error} Error
*/
int ProquintIsProquint(char *str)
int ipfs_proquint_is_proquint(char *str)
{
int i, c, l = strlen(str);
@ -89,7 +89,7 @@ int ProquintIsProquint(char *str)
*
* @return {string} The given byte slice as an identifier.
*/
char *ProquintEncode(char *buf, int size)
char *ipfs_proquint_encode(char *buf, int size)
{
char *ret;
int i, c;
@ -132,14 +132,14 @@ char *ProquintEncode(char *buf, int size)
*
* @return {[]byte} The identifier as a byte slice.
*/
char *ProquintDecode(char *str)
char *ipfs_proquint_decode(char *str)
{
char *ret;
int i, c, l = strlen(str);
uint16_t x;
// make sure its a valid Proquint string.
if (!ProquintIsProquint(str) && ((l+1) % 3)==0) {
if (!ipfs_proquint_is_proquint(str) && ((l+1) % 3)==0) {
return NULL;
}
@ -163,16 +163,16 @@ char *ProquintDecode(char *str)
}
// resolveOnce implements resolver. Decodes the proquint string.
int ProquintResolveOnce (char **p, char *name)
int ipfs_proquint_resolve_once (char **p, char *name)
{
int err = ProquintIsProquint(name);
int err = ipfs_proquint_is_proquint(name);
char buf[500];
if (err) {
*p = NULL;
err = ErrInvalidProquint;
} else {
err = ParsePath(buf, ProquintDecode(name));
err = ipfs_path_parse(buf, ipfs_proquint_decode(name));
if (!err) {
*p = malloc (strlen(buf) + 1);
if (p) {

View File

@ -16,12 +16,12 @@ int main(void) {
NULL};
for (i = 0 ; p[i] ; i++) {
r = ProquintDecode (p[i]);
r = ipfs_proquint_decode (p[i]);
if (r) {
struct in_addr ip_addr;
memcpy (&(ip_addr.s_addr), r, sizeof(ip_addr.s_addr));
printf ("%s\t%s", p[i], inet_ntoa(ip_addr));
s = ProquintEncode(r, sizeof(ip_addr.s_addr));
s = ipfs_proquint_encode(r, sizeof(ip_addr.s_addr));
free (r);
if (s) {
printf ("\t%s", s);

View File

@ -5,7 +5,7 @@
#include <ipfs/path/path.h>
// FromCid safely converts a cid.Cid type to a Path type
char* PathFromCid (struct Cid *c)
char* ipfs_path_from_cid (struct Cid *c)
{
const char prefix[] = "/ipfs/";
char *rpath, *cidstr = CidString(c);
@ -17,7 +17,7 @@ char* PathFromCid (struct Cid *c)
return rpath;
}
char** SplitN (char *p, char *delim, int n)
char** ipfs_path_split_n (char *p, char *delim, int n)
{
char *c, **r, *rbuf;
int i, dlen = strlen(delim);
@ -62,15 +62,15 @@ char** SplitN (char *p, char *delim, int n)
return r;
}
char** Segments (char *p)
char** ipfs_path_split_segments (char *p)
{
if (*p == '/') p++; // Ignore leading slash
return SplitN (p, "/", -1);
return ipfs_path_split_n (p, "/", -1);
}
// Count Segments
int SegmentsLength (char **s)
// Count segments
int ipfs_path_segments_length (char **s)
{
int r = 0;
@ -81,8 +81,8 @@ int SegmentsLength (char **s)
return r;
}
// free memory allocated by Segments
void FreeSegments (char ***s)
// free memory allocated by ipfs_path_split_segments
void ipfs_path_free_segments (char ***s)
{
if (*s && **s) {
free(**s); // free string buffer
@ -91,25 +91,25 @@ void FreeSegments (char ***s)
}
}
// IsJustAKey returns true if the path is of the form <key> or /ipfs/<key>.
int IsJustAKey (char *p)
// ipfs_path_is_just_a_key returns true if the path is of the form <key> or /ipfs/<key>.
int ipfs_path_is_just_a_key (char *p)
{
char **parts;
int ret = 0;
parts = Segments (p);
parts = ipfs_path_split_segments (p);
if (parts) {
if (SegmentsLength (parts) == 2 && strcmp (parts[0], "ipfs") == 0) ret++;
FreeSegments(&parts);
if (ipfs_path_segments_length (parts) == 2 && strcmp (parts[0], "ipfs") == 0) ret++;
ipfs_path_free_segments(&parts);
}
return ret;
}
// PopLastSegment returns a new Path without its final segment, and the final
// ipfs_path_pop_last_segment returns a new Path without its final segment, and the final
// segment, separately. If there is no more to pop (the path is just a key),
// the original path is returned.
int PopLastSegment (char **str, char *p)
int ipfs_path_pop_last_segment (char **str, char *p)
{
if (IsJustAKey(p)) return 0;
if (ipfs_path_is_just_a_key(p)) return 0;
*str = strrchr(p, '/');
if (!*str) return ErrBadPath; // error
**str = '\0';
@ -117,7 +117,7 @@ int PopLastSegment (char **str, char *p)
return 0;
}
char *PathFromSegments(char *prefix, char **seg)
char *ipfs_path_from_segments(char *prefix, char **seg)
{
int retlen, i;
char *ret;
@ -140,7 +140,7 @@ char *PathFromSegments(char *prefix, char **seg)
return ret;
}
int ParseCidToPath (char *dst, char *txt)
int ipfs_path_parse_from_cid (char *dst, char *txt)
{
struct Cid *c;
char *r;
@ -153,7 +153,7 @@ int ParseCidToPath (char *dst, char *txt)
return ErrCidDecode;
}
r = PathFromCid(c);
r = ipfs_path_from_cid(c);
if (!r) {
return ErrCidDecode;
@ -163,7 +163,7 @@ int ParseCidToPath (char *dst, char *txt)
return 0;
}
int ParsePath (char *dst, char *txt)
int ipfs_path_parse (char *dst, char *txt)
{
int err, i;
char *c;
@ -176,10 +176,10 @@ int ParsePath (char *dst, char *txt)
if (*txt == '/') {
txt++;
}
err = ParseCidToPath (dst+plen, txt);
if (err == 0) { // only change dst if ParseCidToPath returned success.
err = ipfs_path_parse_from_cid (dst+plen, txt);
if (err == 0) { // only change dst if ipfs_path_parse_from_cid returned success.
// Use memcpy instead of strcpy to avoid overwriting
// result of ParseCidToPath with a null terminator.
// result of ipfs_path_parse_from_cid with a null terminator.
memcpy (dst, prefix, plen);
}
return err;
@ -194,15 +194,15 @@ int ParsePath (char *dst, char *txt)
strcpy (buf, txt+6); // copy to temp buffer.
c = strchr(buf, '/');
if (c) *c = '\0';
return ParseCidToPath(dst, buf);
return ipfs_path_parse_from_cid(dst, buf);
} else if (strcmp (txt, "/ipns/") != 0) {
return ErrBadPath;
}
return 0;
}
int PathIsValid (char *p)
int ipfs_path_is_valid (char *p)
{
char buf[4096];
return ParsePath(buf, p);
return ipfs_path_parse(buf, p);
}

View File

@ -1,20 +1,20 @@
#include "ipfs/cid/cid.h"
#include "ipfs/path/path.h"
Resolver* NewBasicResolver (DAGService *ds)
Resolver* ipfs_path_new_basic_resolver (DAGService *ds)
{
Resolver *ret = malloc(sizeof(Resolver));
if (!ret) return NULL;
ret->DAG = ds;
ret->ResolveOnce = ResolveSingle;
ret->ResolveOnce = ipfs_path_resolve_single;
return ret;
}
// SplitAbsPath clean up and split fpath. It extracts the first component (which
// ipfs_path_split_abs_path clean up and split fpath. It extracts the first component (which
// must be a Multihash) and return it separately.
int SplitAbsPath (struct Cid* cid, char ***parts, char *fpath)
int ipfs_path_split_abs_path (struct Cid* cid, char ***parts, char *fpath)
{
*parts = Segments(fpath);
*parts = ipfs_path_split_segments(fpath);
if (strcmp (**parts, "ipfs") == 0) *parts++;
@ -26,9 +26,9 @@ int SplitAbsPath (struct Cid* cid, char ***parts, char *fpath)
return 0;
}
// ResolvePath fetches the node for given path. It returns the last item
// returned by ResolvePathComponents.
int ResolvePath(Node **nd, Context ctx, Resolver *s, char *fpath)
// ipfs_path_resolve_path fetches the node for given path. It returns the last item
// returned by ipfs_path_resolve_path_components.
int ipfs_path_resolve_path(Node **nd, Context ctx, Resolver *s, char *fpath)
{
int err = IsValid(fpath);
Node **ndd;
@ -36,7 +36,7 @@ int ResolvePath(Node **nd, Context ctx, Resolver *s, char *fpath)
if (err) {
return err;
}
err = ResolvePathComponents(&ndd, ctx, s, fpath);
err = ipfs_path_resolve_path_components(&ndd, ctx, s, fpath);
if (err) {
return err;
}
@ -50,21 +50,21 @@ int ResolvePath(Node **nd, Context ctx, Resolver *s, char *fpath)
return 0;
}
int ResolveSingle(NodeLink **lnk, Context ctx, DAGService *ds, Node **nd, char *name)
int ipfs_path_resolve_single(NodeLink **lnk, Context ctx, DAGService *ds, Node **nd, char *name)
{
return ResolveLink(lnk, name);
return ipfs_path_resolve_link(lnk, name);
}
// ResolvePathComponents fetches the nodes for each segment of the given path.
// ipfs_path_resolve_path_components fetches the nodes for each segment of the given path.
// It uses the first path component as a hash (key) of the first node, then
// resolves all other components walking the links, with ResolveLinks.
int ResolvePathComponents(Node ***nd, Context ctx, Resolver *s, char *fpath)
// resolves all other components walking the links, with ipfs_path_resolve_links.
int ipfs_path_resolve_path_components(Node ***nd, Context ctx, Resolver *s, char *fpath)
{
int err;
struct Cid h;
char **parts;
err = SplitAbsPath(&h, &parts, fpath);
err = ipfs_path_split_abs_path(&h, &parts, fpath);
if (err) {
return err;
}
@ -75,27 +75,27 @@ int ResolvePathComponents(Node ***nd, Context ctx, Resolver *s, char *fpath)
// return DAG_ERR_VAL;
//}
return ResolveLinks(ctx, *nd, parts);
return ipfs_path_resolve_links(ctx, *nd, parts);
}
// ResolveLinks iteratively resolves names by walking the link hierarchy.
// ipfs_path_resolve_links iteratively resolves names by walking the link hierarchy.
// Every node is fetched from the DAGService, resolving the next name.
// Returns the list of nodes forming the path, starting with ndd. This list is
// guaranteed never to be empty.
//
// ResolveLinks(nd, []string{"foo", "bar", "baz"})
// ipfs_path_resolve_links(nd, []string{"foo", "bar", "baz"})
// would retrieve "baz" in ("bar" in ("foo" in nd.Links).Links).Links
int ResolveLinks(Node ***result, Context ctx, Node *ndd, char **names)
int ipfs_path_resolve_links(Node ***result, Context ctx, Node *ndd, char **names)
{
int err, idx = 0;
NodeLink *lnk;
Node *nd;
*result = calloc (sizeof(Node*), SegmentsLength(names) + 1);
*result = calloc (sizeof(Node*), ipfs_path_segments_length(names) + 1);
if (!*result) {
return -1;
}
memset (*result, NULL, sizeof(Node*) * (SegmentsLength(names)+1));
memset (*result, NULL, sizeof(Node*) * (ipfs_path_segments_length(names)+1));
*result[idx++] = ndd;
nd = ndd; // dup arg workaround
@ -107,7 +107,7 @@ int ResolveLinks(Node ***result, Context ctx, Node *ndd, char **names)
//defer cancel()
// for each of the path components
err = ResolveLink(&lnk, *names);
err = ipfs_path_resolve_link(&lnk, *names);
if (err) {
char msg[51];
*result[idx] = NULL;