2016-11-02 18:09:38 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "ipfs/repo/config/addresses.h"
|
|
|
|
|
|
|
|
char* alloc_and_copy(char* source) {
|
|
|
|
unsigned long strLen = strlen(source);
|
|
|
|
char* result = malloc(sizeof(char) * (strLen + 1));
|
2017-10-05 20:14:47 +00:00
|
|
|
if (result != NULL) {
|
|
|
|
strncpy(result, source, strLen);
|
|
|
|
result[strLen] = 0;
|
|
|
|
}
|
2016-11-02 18:09:38 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-04-17 16:58:47 +00:00
|
|
|
int repo_config_addresses_new(struct Addresses** addresses) {
|
2016-11-28 13:09:00 +00:00
|
|
|
*addresses = (struct Addresses*)malloc(sizeof(struct Addresses));
|
|
|
|
if (*addresses == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2017-03-19 12:47:19 +00:00
|
|
|
struct Addresses* addr = *addresses;
|
2016-11-28 13:09:00 +00:00
|
|
|
|
2017-04-17 16:58:47 +00:00
|
|
|
// allocate memory to store api and gateway
|
|
|
|
addr->api = NULL;
|
|
|
|
addr->gateway = NULL;
|
2017-03-19 12:47:19 +00:00
|
|
|
addr->swarm_head = NULL;
|
2016-11-28 13:09:00 +00:00
|
|
|
|
2016-11-02 18:09:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int repo_config_addresses_free(struct Addresses* addresses) {
|
|
|
|
free(addresses->api);
|
|
|
|
free(addresses->gateway);
|
2017-03-19 12:47:19 +00:00
|
|
|
libp2p_utils_linked_list_free(addresses->swarm_head);
|
2016-11-28 13:09:00 +00:00
|
|
|
free(addresses);
|
2016-11-02 18:09:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|