site.c

00001 /*
00002  * site.c
00003  */
00004 
00005 #define LIBNFSNAPI_BUILDING_LIB
00006 
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include "error.h"
00011 #include "mgr.h"
00012 #include "site.h"
00013 
00014 
00015 libnfsnapi_site_t *libnfsnapi_site_create(libnfsnapi_mgr_t *mgr,
00016                                                 const char *short_name)
00017 {
00018         libnfsnapi_site_t *site;
00019 
00020         site = (libnfsnapi_site_t *) malloc(sizeof(libnfsnapi_site_t));
00021         if (!site) {
00022                 mgr->error = LIBNFSNAPI_ERROR_MEMORY;
00023                 return NULL;
00024         }
00025 
00026         site->mgr = mgr;
00027 
00028         site->short_name = strdup(short_name);
00029         if (!site->short_name) {
00030                 mgr->error = LIBNFSNAPI_ERROR_MEMORY;
00031                 free(site);
00032                 return NULL;
00033         }
00034 
00035         return site;
00036 }
00037 
00038 void libnfsnapi_site_destroy(libnfsnapi_site_t *site)
00039 {
00040         free(site->short_name);
00041         free(site);
00042 }
00043 
00044 int libnfsnapi_site_addAlias(libnfsnapi_site_t *site, const char *alias)
00045 {
00046         char *request_uri, *post_data;
00047         int err;
00048 
00049         asprintf(&post_data, "alias=%s", alias);
00050 
00051         asprintf(&request_uri, "/site/%s/addAlias", site->short_name);
00052         err = libnfsnapi_mgr_do(site->mgr, LIBNFSNAPI_MGR_HTTP_POST,
00053                                 request_uri, post_data);
00054         free(request_uri);
00055         free(post_data);
00056 
00057         /* TODO: check result */
00058 
00059         return err;
00060 }
00061 
00062 int libnfsnapi_site_removeAlias(libnfsnapi_site_t *site, const char *alias)
00063 {
00064         char *request_uri, *post_data;
00065         int err;
00066 
00067         asprintf(&post_data, "alias=%s", alias);
00068 
00069         asprintf(&request_uri, "/site/%s/removeAlias", site->short_name);
00070         err = libnfsnapi_mgr_do(site->mgr, LIBNFSNAPI_MGR_HTTP_POST,
00071                                 request_uri, post_data);
00072         free(request_uri);
00073         free(post_data);
00074 
00075         /* TODO: check result */
00076 
00077         return err;
00078 }

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