2016-11-02 18:09:38 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "ipfs/repo/config/swarm.h"
|
|
|
|
|
2016-11-28 13:09:00 +00:00
|
|
|
|
2016-11-02 18:09:38 +00:00
|
|
|
int repo_config_swarm_address_init(struct SwarmAddresses* swarm_addresses, char** addresses, int array_length) {
|
|
|
|
// allocate memory for the addresses array
|
|
|
|
swarm_addresses->addresses = malloc(sizeof(char*) * array_length);
|
|
|
|
if (swarm_addresses->addresses == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// copy in all the strings
|
|
|
|
for(int i = 0; i < array_length; i++) {
|
|
|
|
char* newString = malloc(sizeof(char) * (strlen(addresses[i]) + 1));
|
|
|
|
if (newString == NULL)
|
|
|
|
return 0;
|
|
|
|
strncpy(newString, addresses[i], strlen(addresses[i]));
|
|
|
|
newString[strlen(addresses[i])] = 0;
|
|
|
|
swarm_addresses->addresses[i] = newString;
|
|
|
|
}
|
|
|
|
|
2016-11-03 04:05:29 +00:00
|
|
|
swarm_addresses->num_addresses = array_length;
|
|
|
|
|
2016-11-02 18:09:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-11-28 13:09:00 +00:00
|
|
|
int repo_config_swarm_address_new(struct SwarmAddresses** swarm_addresses) {
|
|
|
|
*swarm_addresses = (struct SwarmAddresses*)malloc(sizeof(struct SwarmAddresses));
|
|
|
|
if (*swarm_addresses == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
(*swarm_addresses)->num_addresses = 0;
|
|
|
|
(*swarm_addresses)->addresses = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-11-02 18:09:38 +00:00
|
|
|
int repo_config_swarm_address_free(struct SwarmAddresses* swarm_addresses) {
|
2016-11-28 13:09:00 +00:00
|
|
|
if (swarm_addresses->addresses != NULL) {
|
|
|
|
for (int i = 0; i < swarm_addresses->num_addresses; i++) {
|
|
|
|
free(swarm_addresses->addresses[i]);
|
|
|
|
}
|
|
|
|
free(swarm_addresses->addresses);
|
2016-11-02 18:09:38 +00:00
|
|
|
}
|
2016-11-28 13:09:00 +00:00
|
|
|
free(swarm_addresses);
|
2016-11-02 18:09:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|