taskrambler  0.1.9
Web server and task management solution.
user.c File Reference
#include "user.h"
#include "uuid.h"
#include "class.h"
#include "interface/serializable.h"
#include "interface/indexable.h"
#include "utils/memory.h"
+ Include dependency graph for user.c:

Go to the source code of this file.

Functions

static int userCtor (void *_this, va_list *params)
 
static void userDtor (void *_this)
 
static void userSerialize (void *_this, unsigned char **serialized, size_t *nserialized)
 
static void userUnserialize (void *_this, const unsigned char *serialized, size_t nserialized)
 
static Uuid userIndexUuid (void *_this, Uuid namespace)
 
 INIT_IFACE (Class, userCtor, userDtor, NULL)
 
 INIT_IFACE (Serializable, userSerialize, userUnserialize)
 
 INIT_IFACE (Indexable, userIndexUuid)
 
 CREATE_CLASS (User, NULL, IFACE(Class), IFACE(Serializable), IFACE(Indexable))
 

Detailed Description

Author
Georg Hopp

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file user.c.

Function Documentation

CREATE_CLASS ( User  ,
NULL  ,
IFACE(Class)  ,
IFACE(Serializable)  ,
IFACE(Indexable)   
)
INIT_IFACE ( Class  ,
userCtor  ,
userDtor  ,
NULL   
)
INIT_IFACE ( Serializable  ,
userSerialize  ,
userUnserialize   
)
INIT_IFACE ( Indexable  ,
userIndexUuid   
)
static int userCtor ( void *  _this,
va_list *  params 
)
static

Definition at line 35 of file user.c.

References memMalloc().

36 {
37  User this = _this;
38  char * username = va_arg(* params, char *);
39 
40  if (NULL != username) {
41  size_t nusername = va_arg(* params, size_t);
42  char * email = va_arg(* params, char *);
43  size_t nemail = va_arg(* params, size_t);
44  char * firstname = va_arg(* params, char *);
45  size_t nfirstname = va_arg(* params, size_t);
46  char * surname = va_arg(* params, char *);
47  size_t nsurname = va_arg(* params, size_t);
48 
49  size_t storage_size =
50  nusername + 1 +
51  nemail + 1 +
52  nfirstname + 1 +
53  nsurname + 1 +
54  4 * sizeof(size_t);
55 
56  this->username = memMalloc(storage_size);
57  memcpy(this->username, username, nusername);
58  this->username[nusername] = '\0';
59 
60  this->email = this->username + nusername + 1;
61  memcpy(this->email, email, nemail);
62  this->email[nemail] = '\0';
63 
64  this->firstname = this->email + nemail + 1;
65  memcpy(this->firstname, firstname, nfirstname);
66  this->firstname[nfirstname] = '\0';
67 
68  this->surname = this->firstname + nfirstname + 1;
69  memcpy(this->surname, surname, nsurname);
70  this->surname[nsurname] = '\0';
71 
72  this->nusername = (size_t *)(this->surname + nsurname + 1);
73  *this->nusername = nusername;
74 
75  this->nemail = this->nusername + 1;
76  *this->nemail = nemail;
77 
78  this->nfirstname = this->nemail + 1;
79  *this->nfirstname = nfirstname;
80 
81  this->nsurname = this->nfirstname + 1;
82  *this->nsurname = nsurname;
83  }
84 
85  return 0;
86 }
void * memMalloc(size_t)
Definition: memory.c:783

+ Here is the call graph for this function:

static void userDtor ( void *  _this)
static

Definition at line 90 of file user.c.

References MEM_FREE.

91 {
92  User this = _this;
93 
94  if (NULL != this->username) {
95  MEM_FREE(this->username);
96  }
97 }
#define MEM_FREE(seg)
Definition: memory.h:28
static Uuid userIndexUuid ( void *  _this,
Uuid  namespace 
)
static

Definition at line 148 of file user.c.

References uuidVersion3().

149 {
150  User this = _this;
151 
152  return uuidVersion3(
153  (unsigned char *)this->username,
154  *this->nusername,
155  namespace);
156 }
Uuid uuidVersion3(const unsigned char *, size_t, Uuid)
Definition: version3.c:39

+ Here is the call graph for this function:

static void userSerialize ( void *  _this,
unsigned char **  serialized,
size_t *  nserialized 
)
static

Definition at line 101 of file user.c.

References memMalloc().

105 {
106  User this = _this;
107 
108  *nserialized =
109  *this->nusername + 1 +
110  *this->nemail + 1 +
111  *this->nfirstname + 1 +
112  *this->nsurname + 1 +
113  4 * sizeof(size_t);
114 
115  *serialized = memMalloc(*nserialized);
116 
117  memcpy(*serialized, this->username, *nserialized);
118 }
void * memMalloc(size_t)
Definition: memory.c:783

+ Here is the call graph for this function:

static void userUnserialize ( void *  _this,
const unsigned char *  serialized,
size_t  nserialized 
)
static

Definition at line 122 of file user.c.

References memMalloc().

126 {
127  User this = _this;
128  size_t * user_data_sizes;
129 
130  this->username = memMalloc(nserialized);
131  memcpy(this->username, serialized, nserialized);
132 
133  user_data_sizes =
134  (size_t *)(this->username + nserialized - 4 * sizeof(size_t));
135 
136  this->nusername = user_data_sizes;
137  this->nemail = user_data_sizes + 1;
138  this->nfirstname = user_data_sizes + 2;
139  this->nsurname = user_data_sizes + 3;
140 
141  this->email = this->username + *this->nusername + 1;
142  this->firstname = this->email + *this->nemail + 1;
143  this->surname = this->firstname + *this->nfirstname + 1;
144 }
void * memMalloc(size_t)
Definition: memory.c:783

+ Here is the call graph for this function: