Commit 79b346559a4b569570afb5ff1550573f2b802c9b

Authored by Georg Hopp
1 parent 36612df0

code with abstraced application compiles again, but does not work correctly, sta…

…rt debugging. refs #24
... ... @@ -64,5 +64,6 @@ AC_CONFIG_FILES([Makefile
64 64 src/socket/Makefile
65 65 src/stream/Makefile
66 66 src/tree/Makefile
  67 + src/application/Makefile
67 68 tests/Makefile])
68 69 AC_OUTPUT
... ...
... ... @@ -24,7 +24,7 @@
24 24 #define __APPLICATION_ADAPTER_HTTP_H__
25 25
26 26 #include "class.h"
27   -#include "application.h"
  27 +#include "application/application.h"
28 28
29 29
30 30 CLASS(ApplicationAdapterHttp) {
... ...
... ... @@ -23,14 +23,17 @@
23 23 #ifndef __APPLICATION_H__
24 24 #define __APPLICATION_H__
25 25
  26 +#include <sys/types.h>
26 27 #include "class.h"
27 28
  29 +#include "session.h"
  30 +#include "hash.h"
28 31 #include "auth/credential.h"
29 32
30 33 struct randval {
31 34 time_t timestamp;
32 35 int value;
33   -}
  36 +};
34 37
35 38 CLASS(Application) {
36 39 Hash active_sessions;
... ... @@ -40,8 +43,10 @@ CLASS(Application) {
40 43
41 44 // this should return a user account....now it only return success or failure.
42 45 int applicationLogin(Application, Credential);
43   -unsigned long applicationSessionStart(Application);
  46 +unsigned long applicationSessionStart(Application, const char *, size_t);
44 47 void applicationSessionStop(Application, unsigned long);
  48 +void applicationSessionUpdate(
  49 + Application, unsigned long, const char *, size_t);
45 50 Session applicationSessionGet(Application, unsigned long);
46 51
47 52 #endif // __HTTP_HEADER_H__
... ...
... ... @@ -36,6 +36,8 @@ CLASS(Hash) {
36 36 void * hashAdd(Hash, void *);
37 37 void * hashDelete(Hash, const char *, size_t);
38 38 void * hashGet(Hash, const char *, size_t);
  39 +void * hashDeleteByVal(Hash, unsigned long);
  40 +void * hashGetByVal(Hash, unsigned long);
39 41 void hashEach(Hash, void (*)(const void*));
40 42
41 43 #endif // __HASH_HASH_H__
... ...
... ... @@ -38,10 +38,6 @@ CLASS(Session) {
38 38 char * username;
39 39 };
40 40
41   -Session sessionAdd(const Session *, Session);
42   -Session sessionGet(const Session *, const unsigned long id);
43   -void sessionDelete(const Session *, const unsigned long id);
44   -
45 41 #endif // __SESSION_H__
46 42
47 43 // vim: set ts=4 sw=4:
... ...
... ... @@ -11,7 +11,8 @@ UTILS = utils/hash.c \
11 11 utils/signalHandling.c \
12 12 utils/mime_type.c
13 13
14   -LIBS = ./http/libhttp.a \
  14 +LIBS = ./application/libapplication.a \
  15 + ./http/libhttp.a \
15 16 ./auth/libauth.a \
16 17 ./cbuf/libcbuf.a \
17 18 ./class/libclass.a \
... ... @@ -35,4 +36,4 @@ taskrambler_LDADD = $(LIBS) -lrt -lssl -lldap
35 36 #taskrambler_LDFLAGS = $(COVERAGE_LDFLAGS)
36 37
37 38 SUBDIRS = asset auth cbuf class hash queue http \
38   - logger server session socket stream tree
  39 + logger server session socket stream tree application
... ...
  1 +ACLOCAL_AMFLAGS = -I m4
  2 +AUTOMAKE_OPTIONS = subdir-objects
  3 +
  4 +APPLICATION = application.c \
  5 + login.c \
  6 + session_start.c \
  7 + session_stop.c \
  8 + session_update.c \
  9 + session_get.c
  10 +ADAPTERHTTP = adapter/http/http.c \
  11 + adapter/http/update.c
  12 +
  13 +noinst_LIBRARIES = libapplication.a
  14 +
  15 +libapplication_a_SOURCES = $(APPLICATION) $(ADAPTERHTTP)
  16 +libapplication_a_CFLAGS = $(CFLAGS) -Wall -I ../../include/
... ...
... ... @@ -49,10 +49,14 @@ applicationAdapterHttpDtor(void * _this)
49 49 }
50 50
51 51
52   -void applicationAdapterHttpUpdate(ApplicationAdapterHttp, void *);
  52 +void applicationAdapterHttpUpdate(void *, void *);
53 53
54 54
55   -INIT_IFACE(Class, applicationAdapterHttpCtor, applicationAdapterHttpDtor);
  55 +INIT_IFACE(
  56 + Class,
  57 + applicationAdapterHttpCtor,
  58 + applicationAdapterHttpDtor,
  59 + NULL);
56 60 INIT_IFACE(Observer, applicationAdapterHttpUpdate);
57 61 CREATE_CLASS(
58 62 ApplicationAdapterHttp,
... ...
... ... @@ -22,8 +22,8 @@
22 22
23 23 #define _GNU_SOURCE
24 24
25   -#include <stdio,h>
26   -#include <stdlib,h>
  25 +#include <stdio.h>
  26 +#include <stdlib.h>
27 27 #include <sys/types.h>
28 28
29 29 #include "class.h"
... ... @@ -57,17 +57,17 @@ getSessionId(Hash cookies)
57 57
58 58 static
59 59 void
60   -loginAdapter(Application application, HttpWorker worker)
  60 +loginAdapter(Application application, HttpWorker worker, unsigned long sid)
61 61 {
62 62 HashValue username;
63   - HashValue passeord;
  63 + HashValue password;
64 64 Credential credential;
65 65
66 66 username = hashGet(
67   - worker->current_reqeust->post,
  67 + worker->current_request->post,
68 68 CSTRA("username"));
69 69 password = hashGet(
70   - worker->current_reqeust->post,
  70 + worker->current_request->post,
71 71 CSTRA("password"));
72 72
73 73 if (NULL == username || NULL == password) {
... ... @@ -86,7 +86,10 @@ loginAdapter(Application application, HttpWorker worker)
86 86 size_t nbuf;
87 87
88 88 if (NO_SESSION_SID == sid) {
89   - sid = applicationSessionStart(application);
  89 + sid = applicationSessionStart(
  90 + application,
  91 + (char *)(username->value),
  92 + username->nvalue);
90 93 } else {
91 94 applicationSessionUpdate(
92 95 application,
... ... @@ -99,29 +102,30 @@ loginAdapter(Application application, HttpWorker worker)
99 102
100 103 worker->current_response =
101 104 (HttpMessage)httpResponseSession(
102   - applicationSessionGet(sid));
  105 + applicationSessionGet(application, sid));
103 106
104 107 hashAdd(
105 108 worker->current_response->header,
106   - new(HttpHeader. CSTRA("Set-Cookie"), buffer, nbuf));
  109 + new(HttpHeader, CSTRA("Set-Cookie"), buffer, nbuf));
107 110 } else {
108 111 worker->current_response =
109 112 new(HttpResponse, "HTTP/1.1", 403, "Forbidden");
110 113 }
111 114
112   - delete(credential)
  115 + delete(credential);
113 116 }
114 117
115 118
116 119 void
117   -applicationAdapterHttpUpdate(ApplicationAdapterHttp this, void * subject)
  120 +applicationAdapterHttpUpdate(void * _this, void * subject)
118 121 {
119   - HttpWorker worker = (HttpWorker)subject;
120   - unsigned long sid = getSessionId(worker->current_request->cookies);
  122 + ApplicationAdapterHttp this = _this;
  123 + HttpWorker worker = (HttpWorker)subject;
  124 + unsigned long sid = getSessionId(worker->current_request->cookies);
121 125
122 126 if (0 == strcmp("POST", worker->current_request->method)) {
123 127 if (0 == strcmp("/login/", worker->current_request->path)) {
124   - loginAdapter(this->application, worker);
  128 + loginAdapter(this->application, worker, sid);
125 129 return;
126 130 }
127 131 }
... ... @@ -130,18 +134,18 @@ applicationAdapterHttpUpdate(ApplicationAdapterHttp this, void * subject)
130 134 if (0 == strcmp("/sessinfo/", worker->current_request->path)) {
131 135 worker->current_response =
132 136 (HttpMessage)httpResponseSession(
133   - applicationSessionGet(sid));
  137 + applicationSessionGet(this->application, sid));
134 138 return;
135 139 }
136 140
137 141 if (0 == strcmp("/sess/", worker->current_request->path)) {
138 142 if (NO_SESSION_SID == sid) {
139   - sid = applicationSessionStart(application);
  143 + sid = applicationSessionStart(this->application, NULL, 0);
140 144 }
141 145
142 146 worker->current_response =
143 147 (HttpMessage)httpResponseSession(
144   - applicationSessionGet(sid));
  148 + applicationSessionGet(this->application, sid));
145 149 return;
146 150 }
147 151
... ...
... ... @@ -25,6 +25,7 @@
25 25 #include <stdarg.h>
26 26
27 27 #include "class.h"
  28 +#include "hash.h"
28 29 #include "application/application.h"
29 30
30 31 #include "utils/memory.h"
... ... @@ -36,7 +37,9 @@ applicationCtor(void * _this, va_list * params)
36 37 Application this = _this;
37 38
38 39 this->val = va_arg(*params, struct randval *);
39   - this->auth = va_arg(* params, void *);
  40 + this->auth = va_arg(*params, void *);
  41 +
  42 + this->active_sessions = new(Hash);
40 43
41 44 return 0;
42 45 }
... ... @@ -45,10 +48,13 @@ static
45 48 void
46 49 applicationDtor(void * _this)
47 50 {
  51 + Application this = _this;
  52 +
  53 + delete(this->active_sessions);
48 54 }
49 55
50 56
51   -INIT_IFACE(Class, applicationCtor, applicationDtor);
  57 +INIT_IFACE(Class, applicationCtor, applicationDtor, NULL);
52 58 CREATE_CLASS(Application, NULL, IFACE(Class));
53 59
54 60 // vim: set ts=4 sw=4:
... ...
  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 <stdio.h>
  26 +#include <stdlib.h>
  27 +#include <sys/types.h>
  28 +
  29 +#include "class.h"
  30 +#include "auth.h"
  31 +
  32 +#include "utils/memory.h"
  33 +#include "application/application.h"
  34 +
  35 +
  36 +int
  37 +applicationLogin(Application this, Credential credential)
  38 +{
  39 + return authenticate(this->auth, credential);
  40 +}
  41 +
  42 +// vim: set ts=4 sw=4:
... ...
... ... @@ -20,32 +20,22 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#include <search.h>
24   -#include <time.h>
  23 +#define _GNU_SOURCE
25 24
  25 +#include <sys/types.h>
  26 +
  27 +#include "class.h"
26 28 #include "session.h"
  29 +#include "hash.h"
  30 +#include "application/application.h"
27 31
  32 +#include "utils/memory.h"
28 33
29   -static
30   -inline
31   -int
32   -sessionGetComp(const void * _a, const void * _b)
33   -{
34   - unsigned long a = *(unsigned long *)_a;
35   - Session b = (Session)_b;
36   - return (a < b->id)? -1 : (a > b->id)? 1 : 0;
37   -}
38 34
39 35 Session
40   -sessionGet(const Session * root, const unsigned long id)
  36 +applicationSessionGet(Application this, unsigned long sid)
41 37 {
42   - Session * found = tfind(&id, (void**)root, sessionGetComp);
43   -
44   - if (NULL == found) {
45   - return NULL;
46   - }
47   -
48   - return *found;
  38 + return hashGetByVal(this->active_sessions, sid);
49 39 }
50 40
51 41 // vim: set ts=4 sw=4:
... ...
... ... @@ -20,39 +20,26 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#include <search.h>
  23 +#define _GNU_SOURCE
  24 +
  25 +#include <sys/types.h>
24 26
25   -#include "session.h"
26 27 #include "class.h"
  28 +#include "session.h"
  29 +#include "hash.h"
  30 +#include "application/application.h"
27 31
  32 +#include "utils/memory.h"
28 33
29   -static
30   -inline
31   -int
32   -sessionAddComp(const void * _a, const void * _b)
33   -{
34   - Session a = (Session)_a;
35   - Session b = (Session)_b;
36   - return (a->id < b->id)? -1 : (a->id > b->id)? 1 : 0;
37   -}
38 34
39   -Session
40   -sessionAdd(const Session * root, Session session)
  35 +unsigned long
  36 +applicationSessionStart(Application this, const char * name, size_t nname)
41 37 {
42   - Session * found = tsearch(session, (void**)root, sessionAddComp);
43   -
44   - if (NULL == found) {
45   - return NULL;
46   - }
  38 + Session session = new(Session, name, nname);
47 39
48   - if (*found != session) {
49   - /**
50   - * \todo this should not happen, so do some logging here.
51   - */
52   - delete(session);
53   - }
  40 + hashAdd(this->active_sessions, session);
54 41
55   - return *found;
  42 + return session->id;
56 43 }
57 44
58 45 // vim: set ts=4 sw=4:
... ...
... ... @@ -20,26 +20,22 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#include <search.h>
  23 +#define _GNU_SOURCE
  24 +
  25 +#include <sys/types.h>
24 26
25   -#include "session.h"
26 27 #include "class.h"
  28 +#include "session.h"
  29 +#include "hash.h"
  30 +#include "application/application.h"
27 31
  32 +#include "utils/memory.h"
28 33
29   -static
30   -inline
31   -int
32   -sessionDeleteComp(const void * _a, const void * _b)
33   -{
34   - unsigned long a = *(unsigned long *)_a;
35   - Session b = (Session)_b;
36   - return (a < b->id)? -1 : (a > b->id)? 1 : 0;
37   -}
38 34
39 35 void
40   -sessionDelete(const Session * root, const unsigned long id)
  36 +applicationSessionStop(Application this, unsigned long sid)
41 37 {
42   - tdelete(&id, (void**)root, sessionDeleteComp);
  38 + hashDeleteByVal(this->active_sessions, sid);
43 39 }
44 40
45 41 // vim: set ts=4 sw=4:
... ...
  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 <string.h>
  26 +#include <sys/types.h>
  27 +
  28 +#include "class.h"
  29 +#include "session.h"
  30 +#include "hash.h"
  31 +#include "application/application.h"
  32 +
  33 +#include "utils/memory.h"
  34 +
  35 +
  36 +void
  37 +applicationSessionUpdate(
  38 + Application this,
  39 + unsigned long sid,
  40 + const char * name,
  41 + size_t nname)
  42 +{
  43 + Session session = hashGetByVal(this->active_sessions, sid);
  44 +
  45 + MEM_FREE(session->username);
  46 +
  47 + session->username = memMalloc(nname + 1);
  48 + session->username[nname] = 0;
  49 + memcpy(session->username, name, nname);
  50 +}
  51 +
  52 +// vim: set ts=4 sw=4:
... ...
... ... @@ -55,4 +55,12 @@ hashDelete(Hash this, const char * search, size_t nsearch)
55 55 return found;
56 56 }
57 57
  58 +void *
  59 +hashDeleteByVal(Hash this, unsigned long hash)
  60 +{
  61 + void * found = treeDelete(&(this->root), &hash, hashDeleteComp);
  62 +
  63 + return found;
  64 +}
  65 +
58 66 // vim: set ts=4 sw=4:
... ...
... ... @@ -56,4 +56,11 @@ hashGet(Hash this, const char * search, size_t nsearch)
56 56 return found;
57 57 }
58 58
  59 +void *
  60 +hashGetByVal(Hash this, unsigned long hash)
  61 +{
  62 + void * found = treeFind(this->root, &hash, hashGetComp);
  63 +
  64 + return found;
  65 +}
59 66 // vim: set ts=4 sw=4:
... ...
... ... @@ -41,6 +41,8 @@
41 41 #include "http/response.h"
42 42 #include "http/parser.h"
43 43
  44 +#include "interface/subject.h"
  45 +
44 46 #include "utils/memory.h"
45 47 #include "utils/mime_type.h"
46 48 #include "commons.h"
... ...
... ... @@ -3,5 +3,5 @@ AUTOMAKE_OPTIONS = subdir-objects
3 3
4 4 noinst_LIBRARIES = libsession.a
5 5
6   -libsession_a_SOURCES = session.c add.c get.c delete.c
  6 +libsession_a_SOURCES = session.c
7 7 libsession_a_CFLAGS = $(CFLAGS) -Wall -I ../../include/
... ...
... ... @@ -28,6 +28,7 @@
28 28 #include <sys/types.h>
29 29
30 30 #include "session.h"
  31 +#include "hash.h"
31 32 #include "class.h"
32 33
33 34 #include "utils/hash.h"
... ... @@ -61,7 +62,23 @@ sessionDtor(void * _this)
61 62 MEM_FREE(this->username);
62 63 }
63 64
  65 +static
  66 +unsigned long
  67 +sessionGetId(void * _this)
  68 +{
  69 + Session this = _this;
  70 +
  71 + return this->id;
  72 +}
  73 +
  74 +static
  75 +void
  76 +sessionHandleDouble(void * _this, void * _doub)
  77 +{
  78 +}
  79 +
64 80 INIT_IFACE(Class, sessionCtor, sessionDtor, NULL);
65   -CREATE_CLASS(Session, NULL, IFACE(Class));
  81 +INIT_IFACE(Hashable, sessionGetId, sessionHandleDouble);
  82 +CREATE_CLASS(Session, NULL, IFACE(Class), IFACE(Hashable));
66 83
67 84 // vim: set ts=4 sw=4:
... ...
... ... @@ -39,6 +39,9 @@
39 39 #include "logger.h"
40 40 #include "http/worker.h"
41 41 #include "auth.h"
  42 +#include "application/application.h"
  43 +#include "application/adapter/http.h"
  44 +#include "interface/subject.h"
42 45
43 46 #include "class.h"
44 47 #include "logger.h"
... ... @@ -135,8 +138,8 @@ main()
135 138 default:
136 139 {
137 140 AuthLdap auth;
138   - //Application application;
139   - //ApplicationAdapterHttp adapterHttp;
  141 + Application application;
  142 + ApplicationAdapterHttp adapterHttp;
140 143 HttpWorker worker;
141 144 Server server;
142 145
... ... @@ -199,10 +202,12 @@ main()
199 202 }
200 203 } while (!WIFEXITED(status) && !WIFSIGNALED(status));
201 204
202   - if (NULL != server) delete(server);
203   - if (NULL != worker) delete(worker);
204   - if (NULL != auth) delete(auth);
205   - if (NULL != logger) delete(logger);
  205 + delete(server);
  206 + delete(worker);
  207 + delete(adapterHttp);
  208 + delete(application);
  209 + delete(auth);
  210 + delete(logger);
206 211
207 212 clearMimeTypes();
208 213 assetPoolCleanup();
... ...
Please register or login to post a comment