dns.c

00001 /*
00002  * dns.c
00003  */
00004 
00005 #define LIBNFSNAPI_BUILDING_LIB
00006 
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include "dns.h"
00011 #include "error.h"
00012 #include "mgr.h"
00013 
00014 
00015 libnfsnapi_dns_t *libnfsnapi_dns_create(libnfsnapi_mgr_t *mgr,
00016                                                 const char *domain)
00017 {
00018         libnfsnapi_dns_t *dns;
00019 
00020         dns = (libnfsnapi_dns_t *) malloc(sizeof(libnfsnapi_dns_t));
00021         if (!dns) {
00022                 mgr->error = LIBNFSNAPI_ERROR_MEMORY;
00023                 return NULL;
00024         }
00025 
00026         dns->mgr = mgr;
00027 
00028         dns->domain = strdup(domain);
00029         if (!dns->domain) {
00030                 mgr->error = LIBNFSNAPI_ERROR_MEMORY;
00031                 free(dns);
00032                 return NULL;
00033         }
00034 
00035         return dns;
00036 }
00037 
00038 void libnfsnapi_dns_destroy(libnfsnapi_dns_t *dns)
00039 {
00040         free(dns->domain);
00041         free(dns);
00042 }
00043 
00044 /* Returns minTTL in seconds, or a negative number on error. */
00045 int libnfsnapi_dns_balance(libnfsnapi_dns_t *dns)
00046 {
00047         char *request_uri;
00048         int err;
00049 
00050         asprintf(&request_uri, "/dns/%s/minTTL", dns->domain);
00051         if (!request_uri) {
00052                 dns->mgr->error = LIBNFSNAPI_ERROR_MEMORY;
00053                 return -1;
00054         }
00055         err = libnfsnapi_mgr_do(dns->mgr, LIBNFSNAPI_MGR_HTTP_GET,
00056                                 request_uri, NULL);
00057         free(request_uri);
00058 
00059         if (err)
00060                 return -1;
00061 
00062         return libnfsnapi_mgr_result_int(dns->mgr);
00063 }
00064 

Generated on Sat Jan 13 17:42:28 2007 for libNFSNapi by  doxygen 1.4.6