Server 0.0.1
HTTP/REST server implementation

src/session/session.c

Go to the documentation of this file.
00001 
00023 #include <time.h>
00024 #include <stdarg.h>
00025 #include <stdlib.h>
00026 #include <string.h>
00027 #include <stdio.h>
00028 #include <sys/types.h>
00029 
00030 #include "session.h"
00031 #include "class.h"
00032 
00033 #include "utils/hash.h"
00034 #include "utils/memory.h"
00035 
00036 
00037 static
00038 int
00039 sessionCtor(void * _this, va_list * params)
00040 {
00041         Session this  = _this;
00042         char * uname  = va_arg(* params, char *);
00043         size_t nuname = va_arg(* params, size_t);
00044 
00045         this->livetime = time(NULL) + SESSION_LIVETIME;
00046         this->id       = sdbm((unsigned char *)uname, nuname) ^ this->livetime;
00047 
00048         this->username = malloc(nuname + 1);
00049         this->username[nuname] = 0;
00050         memcpy(this->username, uname, nuname);
00051 
00052         return 0;
00053 }
00054 
00055 static
00056 void
00057 sessionDtor(void * _this)
00058 {
00059         Session this = _this;
00060 
00061         FREE(this->username);
00062 }
00063 
00064 INIT_IFACE(Class, sessionCtor, sessionDtor, NULL);
00065 CREATE_CLASS(Session, NULL, IFACE(Class));
00066 
00067 // vim: set ts=4 sw=4:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines