taskrambler  0.1.9
Web server and task management solution.
application.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 #define _GNU_SOURCE
24 
25 #include <stdarg.h>
26 
27 #include "class.h"
28 #include "hash.h"
29 #include "uuid.h"
31 #include "storage/storage.h"
32 
33 #include "utils/memory.h"
34 #include "config.h"
35 
36 static
37 int
38 applicationCtor(void * _this, va_list * params)
39 {
40  Application this = _this;
41  size_t i;
42 
43  this->val = va_arg(*params, struct randval *);
44 
45  /**
46  * \todo for both of these...each user should be identified
47  * by a number...that way I could use that number in the
48  * passwords db and no direct association between email and
49  * password could be made when someone get the hands on the
50  * password database.
51  */
52  this->users = va_arg(*params, Storage);
53  this->passwords = va_arg(*params, Storage);
54  //this->roles = va_arg(*params, Storage);
55 
56  this->user_namespace = uuidParse(va_arg(*params, char *));
57 
58  this->auth = va_arg(*params, void *);
59 
60  this->active_sessions = memCalloc(SESSION_LIVETIME, sizeof(Hash));
61  for (i=0; i<SESSION_LIVETIME; i++) {
62  this->active_sessions[i] = new(Hash);
63  }
64 
65  this->version = VERSION;
66  this->loc = LOC;
67 
68  return 0;
69 }
70 
71 static
72 void
73 applicationDtor(void * _this)
74 {
75  Application this = _this;
76  size_t i;
77 
78  delete(this->user_namespace);
79 
80  for (i=0; i<SESSION_LIVETIME; i++) {
81  delete(this->active_sessions[i]);
82  }
83 
84  MEM_FREE(this->active_sessions);
85  MEM_FREE(this->auth);
86 }
87 
88 
90 CREATE_CLASS(Application, NULL, IFACE(Class));
91 
92 // vim: set ts=4 sw=4:
#define MEM_FREE(seg)
Definition: memory.h:28
Uuid uuidParse(const UuidString)
Definition: uuid/parse.c:30
static int applicationCtor(void *_this, va_list *params)
Definition: application.c:38
#define IFACE(name)
Definition: interface.h:34
static void applicationDtor(void *_this)
Definition: application.c:73
CREATE_CLASS(Application, NULL, IFACE(Class))
INIT_IFACE(Class, applicationCtor, applicationDtor, NULL)
void * memCalloc(size_t, size_t)
Definition: memory.c:818
#define SESSION_LIVETIME
Definition: session.h:33