forked from agorise/c-ipfs
Some changes at namesys/pb
This commit is contained in:
parent
a60300d160
commit
41b7579f21
2 changed files with 34 additions and 6 deletions
|
@ -1,14 +1,19 @@
|
|||
#ifndef IPNS_NAMESYS_PB_H
|
||||
#define IPNS_NAMESYS_PB_H
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int IpnsEntry_ValidityType;
|
||||
typedef int32_t IpnsEntry_ValidityType;
|
||||
|
||||
struct ipns_entry {
|
||||
// TODO
|
||||
struct routingResolver *cache;
|
||||
struct stime *eol;
|
||||
char *value;
|
||||
char *signature;
|
||||
int32_t *validityType;
|
||||
char *validity;
|
||||
uint64_t *sequence;
|
||||
uint64_t *ttl;
|
||||
struct routingResolver *cache; // cache and eol should be the last items.
|
||||
struct timespec *eol;
|
||||
};
|
||||
|
||||
struct namesys_pb {
|
||||
// TODO
|
||||
struct ipns_entry *IpnsEntry;
|
||||
|
@ -23,8 +28,9 @@
|
|||
};
|
||||
|
||||
int IpnsEntry_ValidityType_value (char *s);
|
||||
struct ipns_entry* ipfs_namesys_pb_new_ipns_entry ();
|
||||
char* ipfs_namesys_pb_get_validity (struct ipns_entry*);
|
||||
char* ipfs_ipns_entry_data_for_sig(struct ipns_entry*);
|
||||
char* ipns_entry_data_for_sig(struct ipns_entry*);
|
||||
char* ipfs_ipns_entry_get_signature(struct ipns_entry*);
|
||||
int ipfs_namesys_pb_get_value (char**, struct ipns_entry*);
|
||||
IpnsEntry_ValidityType ipfs_namesys_pb_get_validity_type (struct ipns_entry*);
|
||||
|
|
22
namesys/pb.c
22
namesys/pb.c
|
@ -1,4 +1,5 @@
|
|||
#include <string.h>
|
||||
#include "ipfs/namesys/routing.h"
|
||||
#include "ipfs/namesys/pb.h"
|
||||
|
||||
int IpnsEntry_ValidityType_value (char *s)
|
||||
|
@ -17,3 +18,24 @@ int IpnsEntry_ValidityType_value (char *s)
|
|||
|
||||
return -1; // not found.
|
||||
}
|
||||
|
||||
struct ipns_entry* ipfs_namesys_pb_new_ipns_entry ()
|
||||
{
|
||||
return calloc(1, sizeof (struct ipns_entry));
|
||||
}
|
||||
|
||||
void ipfs_namesys_ipnsentry_reset (struct ipns_entry *m)
|
||||
{
|
||||
if (m) {
|
||||
// ipns_entry is an struct of pointers,
|
||||
// so we can access as an array of pointers.
|
||||
char **a = (char **)m;
|
||||
int i, l = (sizeof (struct ipns_entry) / sizeof (void*)) - 2; // avoid last 2 pointers, cache and eol.
|
||||
for (i = 0 ; i < l ; i++) {
|
||||
if (a[i]) {
|
||||
free (a[i]); // free allocated pointers,
|
||||
a[i] = NULL; // and mark as free.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue