Browse Source

code with abstraced application compiles again, but does not work correctly, start debugging. refs #24

release0.1.5
Georg Hopp 12 years ago
parent
commit
79b346559a
  1. 1
      configure.ac
  2. 2
      include/application/adapter/http.h
  3. 9
      include/application/application.h
  4. 2
      include/hash/hash.h
  5. 4
      include/session.h
  6. 5
      src/Makefile.am
  7. 16
      src/application/Makefile.am
  8. 8
      src/application/adapter/http/http.c
  9. 34
      src/application/adapter/http/update.c
  10. 10
      src/application/application.c
  11. 42
      src/application/login.c
  12. 28
      src/application/session_get.c
  13. 37
      src/application/session_start.c
  14. 22
      src/application/session_stop.c
  15. 52
      src/application/session_update.c
  16. 8
      src/hash/delete.c
  17. 7
      src/hash/get.c
  18. 2
      src/http/worker/process.c
  19. 2
      src/session/Makefile.am
  20. 19
      src/session/session.c
  21. 17
      src/taskrambler.c

1
configure.ac

@ -64,5 +64,6 @@ AC_CONFIG_FILES([Makefile
src/socket/Makefile
src/stream/Makefile
src/tree/Makefile
src/application/Makefile
tests/Makefile])
AC_OUTPUT

2
include/application/adapter/http.h

@ -24,7 +24,7 @@
#define __APPLICATION_ADAPTER_HTTP_H__
#include "class.h"
#include "application.h"
#include "application/application.h"
CLASS(ApplicationAdapterHttp) {

9
include/application/application.h

@ -23,14 +23,17 @@
#ifndef __APPLICATION_H__
#define __APPLICATION_H__
#include <sys/types.h>
#include "class.h"
#include "session.h"
#include "hash.h"
#include "auth/credential.h"
struct randval {
time_t timestamp;
int value;
}
};
CLASS(Application) {
Hash active_sessions;
@ -40,8 +43,10 @@ CLASS(Application) {
// this should return a user account....now it only return success or failure.
int applicationLogin(Application, Credential);
unsigned long applicationSessionStart(Application);
unsigned long applicationSessionStart(Application, const char *, size_t);
void applicationSessionStop(Application, unsigned long);
void applicationSessionUpdate(
Application, unsigned long, const char *, size_t);
Session applicationSessionGet(Application, unsigned long);
#endif // __HTTP_HEADER_H__

2
include/hash/hash.h

@ -36,6 +36,8 @@ CLASS(Hash) {
void * hashAdd(Hash, void *);
void * hashDelete(Hash, const char *, size_t);
void * hashGet(Hash, const char *, size_t);
void * hashDeleteByVal(Hash, unsigned long);
void * hashGetByVal(Hash, unsigned long);
void hashEach(Hash, void (*)(const void*));
#endif // __HASH_HASH_H__

4
include/session.h

@ -38,10 +38,6 @@ CLASS(Session) {
char * username;
};
Session sessionAdd(const Session *, Session);
Session sessionGet(const Session *, const unsigned long id);
void sessionDelete(const Session *, const unsigned long id);
#endif // __SESSION_H__
// vim: set ts=4 sw=4:

5
src/Makefile.am

@ -11,7 +11,8 @@ UTILS = utils/hash.c \
utils/signalHandling.c \
utils/mime_type.c
LIBS = ./http/libhttp.a \
LIBS = ./application/libapplication.a \
./http/libhttp.a \
./auth/libauth.a \
./cbuf/libcbuf.a \
./class/libclass.a \
@ -35,4 +36,4 @@ taskrambler_LDADD = $(LIBS) -lrt -lssl -lldap
#taskrambler_LDFLAGS = $(COVERAGE_LDFLAGS)
SUBDIRS = asset auth cbuf class hash queue http \
logger server session socket stream tree
logger server session socket stream tree application

16
src/application/Makefile.am

@ -0,0 +1,16 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
APPLICATION = application.c \
login.c \
session_start.c \
session_stop.c \
session_update.c \
session_get.c
ADAPTERHTTP = adapter/http/http.c \
adapter/http/update.c
noinst_LIBRARIES = libapplication.a
libapplication_a_SOURCES = $(APPLICATION) $(ADAPTERHTTP)
libapplication_a_CFLAGS = $(CFLAGS) -Wall -I ../../include/

8
src/application/adapter/http/http.c

@ -49,10 +49,14 @@ applicationAdapterHttpDtor(void * _this)
}
void applicationAdapterHttpUpdate(ApplicationAdapterHttp, void *);
void applicationAdapterHttpUpdate(void *, void *);
INIT_IFACE(Class, applicationAdapterHttpCtor, applicationAdapterHttpDtor);
INIT_IFACE(
Class,
applicationAdapterHttpCtor,
applicationAdapterHttpDtor,
NULL);
INIT_IFACE(Observer, applicationAdapterHttpUpdate);
CREATE_CLASS(
ApplicationAdapterHttp,

34
src/application/adapter/http/update.c

@ -22,8 +22,8 @@
#define _GNU_SOURCE
#include <stdio,h>
#include <stdlib,h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
@ -57,17 +57,17 @@ getSessionId(Hash cookies)
static
void
loginAdapter(Application application, HttpWorker worker)
loginAdapter(Application application, HttpWorker worker, unsigned long sid)
{
HashValue username;
HashValue passeord;
HashValue password;
Credential credential;
username = hashGet(
worker->current_reqeust->post,
worker->current_request->post,
CSTRA("username"));
password = hashGet(
worker->current_reqeust->post,
worker->current_request->post,
CSTRA("password"));
if (NULL == username || NULL == password) {
@ -86,7 +86,10 @@ loginAdapter(Application application, HttpWorker worker)
size_t nbuf;
if (NO_SESSION_SID == sid) {
sid = applicationSessionStart(application);
sid = applicationSessionStart(
application,
(char *)(username->value),
username->nvalue);
} else {
applicationSessionUpdate(
application,
@ -99,29 +102,30 @@ loginAdapter(Application application, HttpWorker worker)
worker->current_response =
(HttpMessage)httpResponseSession(
applicationSessionGet(sid));
applicationSessionGet(application, sid));
hashAdd(
worker->current_response->header,
new(HttpHeader. CSTRA("Set-Cookie"), buffer, nbuf));
new(HttpHeader, CSTRA("Set-Cookie"), buffer, nbuf));
} else {
worker->current_response =
new(HttpResponse, "HTTP/1.1", 403, "Forbidden");
}
delete(credential)
delete(credential);
}
void
applicationAdapterHttpUpdate(ApplicationAdapterHttp this, void * subject)
applicationAdapterHttpUpdate(void * _this, void * subject)
{
ApplicationAdapterHttp this = _this;
HttpWorker worker = (HttpWorker)subject;
unsigned long sid = getSessionId(worker->current_request->cookies);
if (0 == strcmp("POST", worker->current_request->method)) {
if (0 == strcmp("/login/", worker->current_request->path)) {
loginAdapter(this->application, worker);
loginAdapter(this->application, worker, sid);
return;
}
}
@ -130,18 +134,18 @@ applicationAdapterHttpUpdate(ApplicationAdapterHttp this, void * subject)
if (0 == strcmp("/sessinfo/", worker->current_request->path)) {
worker->current_response =
(HttpMessage)httpResponseSession(
applicationSessionGet(sid));
applicationSessionGet(this->application, sid));
return;
}
if (0 == strcmp("/sess/", worker->current_request->path)) {
if (NO_SESSION_SID == sid) {
sid = applicationSessionStart(application);
sid = applicationSessionStart(this->application, NULL, 0);
}
worker->current_response =
(HttpMessage)httpResponseSession(
applicationSessionGet(sid));
applicationSessionGet(this->application, sid));
return;
}

10
src/application/application.c

@ -25,6 +25,7 @@
#include <stdarg.h>
#include "class.h"
#include "hash.h"
#include "application/application.h"
#include "utils/memory.h"
@ -36,7 +37,9 @@ applicationCtor(void * _this, va_list * params)
Application this = _this;
this->val = va_arg(*params, struct randval *);
this->auth = va_arg(* params, void *);
this->auth = va_arg(*params, void *);
this->active_sessions = new(Hash);
return 0;
}
@ -45,10 +48,13 @@ static
void
applicationDtor(void * _this)
{
Application this = _this;
delete(this->active_sessions);
}
INIT_IFACE(Class, applicationCtor, applicationDtor);
INIT_IFACE(Class, applicationCtor, applicationDtor, NULL);
CREATE_CLASS(Application, NULL, IFACE(Class));
// vim: set ts=4 sw=4:

42
src/application/login.c

@ -0,0 +1,42 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 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/>.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include "auth.h"
#include "utils/memory.h"
#include "application/application.h"
int
applicationLogin(Application this, Credential credential)
{
return authenticate(this->auth, credential);
}
// vim: set ts=4 sw=4:

28
src/session/get.c → src/application/session_get.c

@ -20,32 +20,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <search.h>
#include <time.h>
#define _GNU_SOURCE
#include <sys/types.h>
#include "class.h"
#include "session.h"
#include "hash.h"
#include "application/application.h"
#include "utils/memory.h"
static
inline
int
sessionGetComp(const void * _a, const void * _b)
{
unsigned long a = *(unsigned long *)_a;
Session b = (Session)_b;
return (a < b->id)? -1 : (a > b->id)? 1 : 0;
}
Session
sessionGet(const Session * root, const unsigned long id)
applicationSessionGet(Application this, unsigned long sid)
{
Session * found = tfind(&id, (void**)root, sessionGetComp);
if (NULL == found) {
return NULL;
}
return *found;
return hashGetByVal(this->active_sessions, sid);
}
// vim: set ts=4 sw=4:

37
src/session/add.c → src/application/session_start.c

@ -20,39 +20,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <search.h>
#define _GNU_SOURCE
#include <sys/types.h>
#include "session.h"
#include "class.h"
#include "session.h"
#include "hash.h"
#include "application/application.h"
#include "utils/memory.h"
static
inline
int
sessionAddComp(const void * _a, const void * _b)
{
Session a = (Session)_a;
Session b = (Session)_b;
return (a->id < b->id)? -1 : (a->id > b->id)? 1 : 0;
}
Session
sessionAdd(const Session * root, Session session)
unsigned long
applicationSessionStart(Application this, const char * name, size_t nname)
{
Session * found = tsearch(session, (void**)root, sessionAddComp);
if (NULL == found) {
return NULL;
}
Session session = new(Session, name, nname);
if (*found != session) {
/**
* \todo this should not happen, so do some logging here.
*/
delete(session);
}
hashAdd(this->active_sessions, session);
return *found;
return session->id;
}
// vim: set ts=4 sw=4:

22
src/session/delete.c → src/application/session_stop.c

@ -20,26 +20,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <search.h>
#define _GNU_SOURCE
#include <sys/types.h>
#include "session.h"
#include "class.h"
#include "session.h"
#include "hash.h"
#include "application/application.h"
#include "utils/memory.h"
static
inline
int
sessionDeleteComp(const void * _a, const void * _b)
{
unsigned long a = *(unsigned long *)_a;
Session b = (Session)_b;
return (a < b->id)? -1 : (a > b->id)? 1 : 0;
}
void
sessionDelete(const Session * root, const unsigned long id)
applicationSessionStop(Application this, unsigned long sid)
{
tdelete(&id, (void**)root, sessionDeleteComp);
hashDeleteByVal(this->active_sessions, sid);
}
// vim: set ts=4 sw=4:

52
src/application/session_update.c

@ -0,0 +1,52 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 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/>.
*/
#define _GNU_SOURCE
#include <string.h>
#include <sys/types.h>
#include "class.h"
#include "session.h"
#include "hash.h"
#include "application/application.h"
#include "utils/memory.h"
void
applicationSessionUpdate(
Application this,
unsigned long sid,
const char * name,
size_t nname)
{
Session session = hashGetByVal(this->active_sessions, sid);
MEM_FREE(session->username);
session->username = memMalloc(nname + 1);
session->username[nname] = 0;
memcpy(session->username, name, nname);
}
// vim: set ts=4 sw=4:

8
src/hash/delete.c

@ -55,4 +55,12 @@ hashDelete(Hash this, const char * search, size_t nsearch)
return found;
}
void *
hashDeleteByVal(Hash this, unsigned long hash)
{
void * found = treeDelete(&(this->root), &hash, hashDeleteComp);
return found;
}
// vim: set ts=4 sw=4:

7
src/hash/get.c

@ -56,4 +56,11 @@ hashGet(Hash this, const char * search, size_t nsearch)
return found;
}
void *
hashGetByVal(Hash this, unsigned long hash)
{
void * found = treeFind(this->root, &hash, hashGetComp);
return found;
}
// vim: set ts=4 sw=4:

2
src/http/worker/process.c

@ -41,6 +41,8 @@
#include "http/response.h"
#include "http/parser.h"
#include "interface/subject.h"
#include "utils/memory.h"
#include "utils/mime_type.h"
#include "commons.h"

2
src/session/Makefile.am

@ -3,5 +3,5 @@ AUTOMAKE_OPTIONS = subdir-objects
noinst_LIBRARIES = libsession.a
libsession_a_SOURCES = session.c add.c get.c delete.c
libsession_a_SOURCES = session.c
libsession_a_CFLAGS = $(CFLAGS) -Wall -I ../../include/

19
src/session/session.c

@ -28,6 +28,7 @@
#include <sys/types.h>
#include "session.h"
#include "hash.h"
#include "class.h"
#include "utils/hash.h"
@ -61,7 +62,23 @@ sessionDtor(void * _this)
MEM_FREE(this->username);
}
static
unsigned long
sessionGetId(void * _this)
{
Session this = _this;
return this->id;
}
static
void
sessionHandleDouble(void * _this, void * _doub)
{
}
INIT_IFACE(Class, sessionCtor, sessionDtor, NULL);
CREATE_CLASS(Session, NULL, IFACE(Class));
INIT_IFACE(Hashable, sessionGetId, sessionHandleDouble);
CREATE_CLASS(Session, NULL, IFACE(Class), IFACE(Hashable));
// vim: set ts=4 sw=4:

17
src/taskrambler.c

@ -39,6 +39,9 @@
#include "logger.h"
#include "http/worker.h"
#include "auth.h"
#include "application/application.h"
#include "application/adapter/http.h"
#include "interface/subject.h"
#include "class.h"
#include "logger.h"
@ -135,8 +138,8 @@ main()
default:
{
AuthLdap auth;
//Application application;
//ApplicationAdapterHttp adapterHttp;
Application application;
ApplicationAdapterHttp adapterHttp;
HttpWorker worker;
Server server;
@ -199,10 +202,12 @@ main()
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
if (NULL != server) delete(server);
if (NULL != worker) delete(worker);
if (NULL != auth) delete(auth);
if (NULL != logger) delete(logger);
delete(server);
delete(worker);
delete(adapterHttp);
delete(application);
delete(auth);
delete(logger);
clearMimeTypes();
assetPoolCleanup();

Loading…
Cancel
Save