2016-11-02 18:09:38 +00:00
|
|
|
//
|
|
|
|
// addresses.c
|
|
|
|
// c-ipfs
|
|
|
|
//
|
|
|
|
// Created by John Jones on 11/2/16.
|
|
|
|
// Copyright © 2016 JMJAtlanta. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#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));
|
|
|
|
strncpy(result, source, strLen);
|
|
|
|
result[strLen] = 0;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-28 13:09:00 +00:00
|
|
|
int repo_config_addresses_new(struct Addresses** addresses, char* api, char* gateway) {
|
|
|
|
*addresses = (struct Addresses*)malloc(sizeof(struct Addresses));
|
|
|
|
if (*addresses == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2016-11-02 18:09:38 +00:00
|
|
|
// allocate memory to store api and gateway
|
2016-11-28 13:09:00 +00:00
|
|
|
(*addresses)->api = alloc_and_copy(api);
|
|
|
|
(*addresses)->gateway = alloc_and_copy(gateway);
|
|
|
|
if ( (*addresses)->api == NULL || (*addresses)->gateway == NULL)
|
2016-11-02 18:09:38 +00:00
|
|
|
return 0;
|
2016-11-28 13:09:00 +00:00
|
|
|
|
|
|
|
// allocate memory for swarm_addresses
|
|
|
|
if (repo_config_swarm_address_new(&((*addresses)->swarm)) == 0)
|
|
|
|
return 0;
|
|
|
|
|
2016-11-02 18:09:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int repo_config_addresses_free(struct Addresses* addresses) {
|
|
|
|
free(addresses->api);
|
|
|
|
free(addresses->gateway);
|
2016-11-28 13:09:00 +00:00
|
|
|
repo_config_swarm_address_free(addresses->swarm);
|
|
|
|
free(addresses);
|
2016-11-02 18:09:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|