email.c

00001 /*
00002  * email.c
00003  */
00004 
00005 #define LIBNFSNAPI_BUILDING_LIB
00006 
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include "email.h"
00011 #include "error.h"
00012 #include "mgr.h"
00013 
00014 
00015 libnfsnapi_email_t *libnfsnapi_email_create(libnfsnapi_mgr_t *mgr,
00016                                                 const char *domain)
00017 {
00018         libnfsnapi_email_t *email;
00019 
00020         email = (libnfsnapi_email_t *) malloc(sizeof(libnfsnapi_email_t));
00021         if (!email) {
00022                 mgr->error = LIBNFSNAPI_ERROR_MEMORY;
00023                 return NULL;
00024         }
00025 
00026         email->mgr = mgr;
00027 
00028         email->domain = strdup(domain);
00029         if (!email->domain) {
00030                 mgr->error = LIBNFSNAPI_ERROR_MEMORY;
00031                 free(email);
00032                 return NULL;
00033         }
00034 
00035         return email;
00036 }
00037 
00038 void libnfsnapi_email_destroy(libnfsnapi_email_t *email)
00039 {
00040         free(email->domain);
00041         free(email);
00042 }
00043 
00044 int libnfsnapi_email_setForward(libnfsnapi_email_t *email, const char *forward,
00045                                 const char *dest_email)
00046 {
00047         char *request_uri, *post_data;
00048         int err;
00049 
00050         /* TODO: any escaping required? */
00051         asprintf(&post_data, "forward=%s&dest_email=%s", forward, dest_email);
00052         if (!post_data) {
00053                 email->mgr->error = LIBNFSNAPI_ERROR_MEMORY;
00054                 return -1;
00055         }
00056 
00057         asprintf(&request_uri, "/email/%s/setForward", email->domain);
00058         if (!request_uri) {
00059                 free(post_data);
00060                 email->mgr->error = LIBNFSNAPI_ERROR_MEMORY;
00061                 return -1;
00062         }
00063         err = libnfsnapi_mgr_do(email->mgr, LIBNFSNAPI_MGR_HTTP_POST,
00064                                 request_uri, post_data);
00065         free(request_uri);
00066         free(post_data);
00067 
00068         /* TODO: check result */
00069 
00070         return err;
00071 }
00072 
00073 int libnfsnapi_email_removeForward(libnfsnapi_email_t *email,
00074                                         const char *forward)
00075 {
00076         char *request_uri, *post_data;
00077         int err;
00078 
00079         asprintf(&post_data, "forward=%s", forward);
00080         if (!post_data) {
00081                 email->mgr->error = LIBNFSNAPI_ERROR_MEMORY;
00082                 return -1;
00083         }
00084 
00085         asprintf(&request_uri, "/email/%s/removeForward", email->domain);
00086         if (!request_uri) {
00087                 free(post_data);
00088                 email->mgr->error = LIBNFSNAPI_ERROR_MEMORY;
00089                 return -1;
00090         }
00091         err = libnfsnapi_mgr_do(email->mgr, LIBNFSNAPI_MGR_HTTP_POST,
00092                                 request_uri, post_data);
00093         free(request_uri);
00094         free(post_data);
00095 
00096         /* TODO: check result */
00097 
00098         return err;
00099 }

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