c-ipfs/namesys/base.c

43 lines
1.1 KiB
C
Raw Permalink Normal View History

2016-11-23 20:19:16 +00:00
#include <string.h>
#include <time.h>
#include "ipfs/cid/cid.h"
#include "ipfs/path/path.h"
#include "ipfs/namesys/namesys.h"
int ipfs_namesys_base_resolve (resolver *r, char **p, char *str, int depth, char **prefixes)
2016-11-23 20:19:16 +00:00
{
int err, i;
char ipfs_prefix[] = "/ipfs/";
for (;;) {
err = r->resolveOnce(p, str);
if (err) {
//log.Warningf("Could not resolve %s", name);
*p = NULL;
return err;
}
//log.Debugf("Resolved %s to %s", name, p.String());
if (memcmp(p, ipfs_prefix, strlen(ipfs_prefix)) == 0) {
// we've bottomed out with an IPFS path
return 0;
}
if (depth == 1) {
return ErrResolveRecursion;
}
for (i = 0 ; prefixes[i] ; i++) {
if (memcmp(*p, prefixes[i], strlen(prefixes[i])) == 0) {
if (ipfs_path_segments_length(prefixes) == 1) {
2016-11-23 20:19:16 +00:00
str += strlen(prefixes[i]);
}
break;
}
}
if ( !prefixes[i] ) {
return 0;
}
if (depth > 1) {
depth--;
}
}
}