taskrambler  v0.1.8
Web server and task management solution.
credential.c
Go to the documentation of this file.
1 /**
2  * \file
3  *
4  * \author Georg Hopp
5  *
6  * \copyright
7  * Copyright © 2012 Georg Hopp
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include <stdarg.h>
24 #include <sys/types.h>
25 #include <stdlib.h>
26 #include <string.h>
27 
28 #include "class.h"
29 #include "utils/memory.h"
30 
31 #include "auth/credential.h"
32 
33 static
34 int
35 credentialCtor(void * _this, va_list * params)
36 {
37  Credential this = _this;
38 
39  this->type = va_arg(* params, CredentialType);
40 
41  switch(this->type) {
42  case CRED_PASSWORD:
43  {
44  char * user, *pass;
45 
46  user = va_arg(* params, char*);
47  CRED_PWD(this).nuser = va_arg(* params, size_t);
48  pass = va_arg(* params, char*);
49  CRED_PWD(this).npass = va_arg(* params, size_t);
50 
51  CRED_PWD(this).user = memMalloc(CRED_PWD(this).nuser + 1);
52  CRED_PWD(this).user[CRED_PWD(this).nuser] = 0;
53  memcpy(CRED_PWD(this).user, user, CRED_PWD(this).nuser);
54 
55  CRED_PWD(this).pass = memMalloc(CRED_PWD(this).npass + 1);
56  CRED_PWD(this).pass[CRED_PWD(this).npass] = 0;
57  memcpy(CRED_PWD(this).pass, pass, CRED_PWD(this).npass);
58  }
59  break;
60 
61  default:
62  return -1;
63  }
64 
65  return 0;
66 }
67 
68 static
69 void
70 credentialDtor(void * _this)
71 {
72  Credential this = _this;
73 
74  switch(this->type) {
75  case CRED_PASSWORD:
76  MEM_FREE(CRED_PWD(this).user);
77  MEM_FREE(CRED_PWD(this).pass);
78  break;
79  }
80 }
81 
83 CREATE_CLASS(Credential, NULL, IFACE(Class));
84 
85 // vim: set ts=4 sw=4:
#define MEM_FREE(seg)
Definition: memory.h:28
INIT_IFACE(Class, credentialCtor, credentialDtor, NULL)
static int credentialCtor(void *_this, va_list *params)
Definition: credential.c:35
void * memMalloc(size_t)
Definition: memory.c:783
#define IFACE(name)
Definition: interface.h:34
CredentialType
Definition: credential.h:32
static void credentialDtor(void *_this)
Definition: credential.c:70
CREATE_CLASS(Credential, NULL, IFACE(Class))
#define CRED_PWD(c)
Definition: credential.h:30