Server 0.0.1
HTTP/REST server implementation

src/auth/credential.c

Go to the documentation of this file.
00001 
00023 #include <stdarg.h>
00024 #include <sys/types.h>
00025 #include <stdlib.h>
00026 #include <string.h>
00027 
00028 #include "class.h"
00029 #include "utils/memory.h"
00030 
00031 #include "auth/credential.h"
00032 
00033 static
00034 int
00035 credentialCtor(void * _this, va_list * params)
00036 {
00037         Credential this = _this;
00038         
00039         this->type = va_arg(* params, CredentialType);
00040 
00041         switch(this->type) {
00042                 case CRED_PASSWORD:
00043                         {
00044                                 char * user, *pass;
00045 
00046                                 user                 = va_arg(* params, char*);
00047                                 CRED_PWD(this).nuser = va_arg(* params, size_t);
00048                                 pass                 = va_arg(* params, char*);
00049                                 CRED_PWD(this).npass = va_arg(* params, size_t);
00050 
00051                                 CRED_PWD(this).user  = malloc(CRED_PWD(this).nuser + 1);
00052                                 CRED_PWD(this).user[CRED_PWD(this).nuser] = 0;
00053                                 memcpy(CRED_PWD(this).user, user, CRED_PWD(this).nuser);
00054 
00055                                 CRED_PWD(this).pass  = malloc(CRED_PWD(this).npass + 1);
00056                                 CRED_PWD(this).pass[CRED_PWD(this).npass] = 0;
00057                                 memcpy(CRED_PWD(this).pass, pass, CRED_PWD(this).npass);
00058                         }
00059                         break;
00060 
00061                 default:
00062                         return -1;
00063         }
00064 
00065         return 0;
00066 }
00067 
00068 static
00069 void
00070 credentialDtor(void * _this)
00071 {
00072         Credential this = _this;
00073 
00074         switch(this->type) {
00075                 case CRED_PASSWORD:
00076                         FREE(CRED_PWD(this).user);
00077                         FREE(CRED_PWD(this).pass);
00078                         break;
00079         }
00080 }
00081 
00082 INIT_IFACE(Class, credentialCtor, credentialDtor, NULL);
00083 CREATE_CLASS(Credential, NULL, IFACE(Class));
00084 
00085 // vim: set ts=4 sw=4:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines