taskrambler  0.1.8
Web server and task management solution.
cookie.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 <stdlib.h>
24 #include <string.h>
25 #include <stdarg.h>
26 #include <sys/types.h>
27 
28 #include "class.h"
29 #include "hash.h"
30 #include "http/cookie.h"
31 
32 #include "utils/hash.h"
33 #include "utils/memory.h"
34 #include "commons.h"
35 
36 
37 static
38 int
39 httpCookieCtor(void * _this, va_list * params)
40 {
41  HttpCookie this = _this;
42  char * key = va_arg(* params, char*);
43  char * value;
44 
45  this->nkey = va_arg(* params, size_t);
46  value = va_arg(* params, char*);
47  this->nvalue = va_arg(* params, size_t);
48 
49  this->key = memMalloc(this->nkey + 1);
50  this->key[this->nkey] = 0;
51  memcpy(this->key, key, this->nkey);
52 
53  this->value = memMalloc(this->nvalue + 1);
54  this->value[this->nvalue] = 0;
55  memcpy(this->value, value, this->nvalue);
56 
57  this->hash = sdbm((unsigned char *)key, nkey);
58 
59  return 0;
60 }
61 
62 static
63 void
64 httpCookieDtor(void * _this, va_list * params)
65 {
66  HttpCookie this = _this;
67 
68  MEM_FREE(this->key);
69  MEM_FREE(this->value);
70  MEM_FREE(this->domain);
71  MEM_FREE(this->path);
72 }
73 
74 static
75 unsigned long
76 httpCookieGetHash(void * _this)
77 {
78  HttpCookie this = _this;
79 
80  return this->hash;
81 }
82 
83 static
84 void
85 httpCookieHandleDouble(void * _this, void * _double)
86 {
87  HttpCookie this = _this;
88  HttpCookie doub = _double;
89 
90  SWAP(char*, this->key, doub->key);
91  SWAP(char*, this->value, doub->value);
92  SWAP(char*, this->domain, doub->domain);
93  SWAP(char*, this->path, doub->path);
94 
95  SWAP(char*, this->nkey, doub->nkey);
96  SWAP(char*, this->nvalue, doub->nvalue);
97 }
98 
99 
102 CREATE_CLASS(HttpCookie, NULL, IFACE(Class), IFACE(Hashable));
103 
104 // vim: set ts=4 sw=4:
#define MEM_FREE(seg)
Definition: memory.h:28
unsigned long sdbm(const unsigned char *, size_t)
Definition: utils/hash.c:45
void * memMalloc(size_t)
Definition: memory.c:783
#define SWAP(type, a, b)
Definition: commons.h:40
#define IFACE(name)
Definition: interface.h:34