diff --git a/include/application/adapter/http.h b/include/application/adapter/http.h index 3c39cd6..44ef4d3 100644 --- a/include/application/adapter/http.h +++ b/include/application/adapter/http.h @@ -32,6 +32,7 @@ TR_CLASS(ApplicationAdapterHttp) { Application application; Router router; }; +TR_INSTANCE_INIT(ApplicationAdapterHttp); #endif // __APPLICATION_ADAPTER_HTTP_H__ diff --git a/include/application/application.h b/include/application/application.h index f8daff8..d8a28a9 100644 --- a/include/application/application.h +++ b/include/application/application.h @@ -67,6 +67,7 @@ TR_CLASS(Application) { const char * version; const char * loc; }; +TR_INSTANCE_INIT(Application); int applicationLogin(Application, Credential, Session); void applicationLogout(Application, Session); diff --git a/include/asset.h b/include/asset.h index 301d12b..198c81b 100644 --- a/include/asset.h +++ b/include/asset.h @@ -49,6 +49,7 @@ TR_CLASS(Asset) { size_t ref_count; }; +TR_INSTANCE_INIT(Asset); Asset assetPoolGet(const char *, size_t); size_t assetPoolRelease(Asset); diff --git a/include/auth/auth.h b/include/auth/auth.h index 2a4b37e..014a9b5 100644 --- a/include/auth/auth.h +++ b/include/auth/auth.h @@ -58,6 +58,7 @@ typedef enum e_AuthModule { TR_CLASS(Auth) { void * auth[MAX_AUTH + 1]; }; +TR_INSTANCE_INIT(Auth); int authCreate(Auth, AuthModule, ...); diff --git a/include/auth/credential.h b/include/auth/credential.h index 1f492aa..613edc0 100644 --- a/include/auth/credential.h +++ b/include/auth/credential.h @@ -48,6 +48,7 @@ TR_CLASS(Credential) { } cred; }; +TR_INSTANCE_INIT(Credential); #endif // __AUTH_CREDENTIAL_H__ diff --git a/include/auth/ldap.h b/include/auth/ldap.h index baffcfb..d9efb6a 100644 --- a/include/auth/ldap.h +++ b/include/auth/ldap.h @@ -35,6 +35,7 @@ TR_CLASS(AuthLdap) { int version; size_t nbase_dn; }; +TR_INSTANCE_INIT(AuthLdap); #endif // __AUTH_LDAP_H__ diff --git a/include/auth/storage.h b/include/auth/storage.h index e00b53a..12a5544 100644 --- a/include/auth/storage.h +++ b/include/auth/storage.h @@ -38,6 +38,7 @@ TR_CLASS(AuthStorage) { Storage store; }; +TR_INSTANCE_INIT(AuthStorage); /** * \todo In future this should use a more general purpose hash diff --git a/include/config/config.h b/include/config/config.h index ab6f959..497c809 100644 --- a/include/config/config.h +++ b/include/config/config.h @@ -34,6 +34,7 @@ TR_CLASS(Config) { char * cnf_file; TR_Hash config; }; +TR_INSTANCE_INIT(Config); ConfigValue configGet(Config, const char *, size_t); diff --git a/include/config/value.h b/include/config/value.h index 049a460..b23001d 100644 --- a/include/config/value.h +++ b/include/config/value.h @@ -48,6 +48,7 @@ TR_CLASS(ConfigValue) { unsigned long hash; }; +TR_INSTANCE_INIT(ConfigValue); #endif // __CONFIG_VALUE_H__ diff --git a/include/http/cookie.h b/include/http/cookie.h index 194b64c..a969ab5 100644 --- a/include/http/cookie.h +++ b/include/http/cookie.h @@ -42,6 +42,7 @@ TR_CLASS(HttpCookie) { size_t nkey; size_t nvalue; }; +TR_INSTANCE_INIT(HttpCookie); char * httpCookieToString(HttpCookie); HttpCookie httpStringToCookie(const char *); diff --git a/include/http/header.h b/include/http/header.h index 8270ce3..d82eda4 100644 --- a/include/http/header.h +++ b/include/http/header.h @@ -40,6 +40,7 @@ TR_CLASS(HttpHeader) { size_t cvalue; //!< count of values up to N_VALUE size_t size; //!< full size of this header }; +TR_INSTANCE_INIT(HttpHeader); size_t httpHeaderToString(HttpHeader, char *); diff --git a/include/http/message.h b/include/http/message.h index c96e454..b29ad12 100644 --- a/include/http/message.h +++ b/include/http/message.h @@ -39,6 +39,7 @@ TR_CLASS(HttpMessage) { int nbody; int dbody; }; +TR_INSTANCE_INIT(HttpMessage); char httpMessageHasKeepAlive(HttpMessage); size_t httpMessageHeaderSizeGet(HttpMessage); diff --git a/include/http/parser.h b/include/http/parser.h index 98f9620..93671a5 100644 --- a/include/http/parser.h +++ b/include/http/parser.h @@ -54,6 +54,7 @@ TR_CLASS(HttpParser) { HttpMessageState state; }; +TR_INSTANCE_INIT(HttpParser); ssize_t httpParserParse(void *, TR_Stream); void httpParserRequestVars(HttpParser); diff --git a/include/http/request.h b/include/http/request.h index 97ee690..c745f84 100644 --- a/include/http/request.h +++ b/include/http/request.h @@ -56,6 +56,7 @@ TR_CLASS(HttpRequest) { TR_Hash post; TR_Hash cookies; }; +TR_INSTANCE_INIT(HttpRequest); HttpMethod httpRequestGetMethodId(HttpRequest); diff --git a/include/http/response.h b/include/http/response.h index b6df1cc..85d3b5d 100644 --- a/include/http/response.h +++ b/include/http/response.h @@ -40,6 +40,7 @@ TR_CLASS(HttpResponse) { unsigned int status; char * reason; }; +TR_INSTANCE_INIT(HttpResponse); HttpResponse httpResponse304( const char *, size_t, diff --git a/include/http/worker.h b/include/http/worker.h index 81ac0f4..6ae1cda 100644 --- a/include/http/worker.h +++ b/include/http/worker.h @@ -40,7 +40,7 @@ TR_CLASS(HttpWorker) { char * id; - TR_Sock socket; + TR_Socket socket; TR_Cbuf pbuf; TR_Hash asset_pool; @@ -55,6 +55,7 @@ TR_CLASS(HttpWorker) { HttpParser parser; HttpWriter writer; }; +TR_INSTANCE_INIT(HttpWorker); #endif // __HTTP_WORKER_H__ diff --git a/include/http/writer.h b/include/http/writer.h index 9ae6b37..30dd12c 100644 --- a/include/http/writer.h +++ b/include/http/writer.h @@ -89,6 +89,7 @@ TR_CLASS(HttpWriter) { HttpWriterState state; }; +TR_INSTANCE_INIT(HttpWriter); ssize_t httpWriterWrite(void *, TR_Stream); diff --git a/include/permission.h b/include/permission.h index 000eccd..9b38283 100644 --- a/include/permission.h +++ b/include/permission.h @@ -52,6 +52,7 @@ TR_CLASS(Permission) { char * resource; ResourceAction action; }; +TR_INSTANCE_INIT(Permission); #endif // __PERMISSION_H__ diff --git a/include/rbac/object.h b/include/rbac/object.h index 77b977c..ce59089 100644 --- a/include/rbac/object.h +++ b/include/rbac/object.h @@ -33,6 +33,7 @@ TR_CLASS(RbacObject) { char * name; size_t nname; }; +TR_INSTANCE_INIT(RbacObject); #endif // __RBAC_OBJECT_H__ diff --git a/include/rbac/operation.h b/include/rbac/operation.h index 495ec96..ce20aea 100644 --- a/include/rbac/operation.h +++ b/include/rbac/operation.h @@ -32,6 +32,7 @@ TR_CLASS(RbacOperation) { char * name; size_t nname; }; +TR_INSTANCE_INIT(RbacOperation); #endif // __RBAC_OPERATION_H__ diff --git a/include/rbac/user.h b/include/rbac/user.h index cff8786..f32639f 100644 --- a/include/rbac/user.h +++ b/include/rbac/user.h @@ -41,6 +41,7 @@ TR_CLASS(RbacUser) { char * name; size_t nname; }; +TR_INSTANCE_INIT(RbacUser); // void userSerialize(User, void **, size_t *); // void userDeserialize(User, void *, size_t); diff --git a/include/role.h b/include/role.h index aaa2ba9..f933860 100644 --- a/include/role.h +++ b/include/role.h @@ -95,7 +95,9 @@ TR_CLASS(Role) { User * users; Hash users_idx; + // end og ROLE definition. }; +TR_INSTANCE_INIT(Role); #endif // __ROLE_H__ diff --git a/include/router.h b/include/router.h index 42f92d1..84677e5 100644 --- a/include/router.h +++ b/include/router.h @@ -51,6 +51,7 @@ TR_CLASS(Router) { char * prefix; size_t nprefix; }; +TR_INSTANCE_INIT(Router); HttpResponse routerRoute(Router, HttpRequest, Session); diff --git a/include/server.h b/include/server.h index 0a3cb16..d126140 100644 --- a/include/server.h +++ b/include/server.h @@ -35,15 +35,15 @@ #include "trio.h" struct conns { - TR_Sock sock; + TR_Socket sock; TR_Stream stream; void * worker; }; TR_CLASS(Server) { TR_Logger logger; - TR_Sock sock; - TR_Sock sockSSL; + TR_Socket sock; + TR_Socket sockSSL; SSL_CTX * ctx; void * worker; @@ -53,6 +53,7 @@ TR_CLASS(Server) { struct conns * conns; }; +TR_INSTANCE_INIT(Server); void serverRun(Server this); diff --git a/include/session.h b/include/session.h index b0b7498..2144f28 100644 --- a/include/session.h +++ b/include/session.h @@ -70,6 +70,7 @@ TR_CLASS(Session) { time_t livetime; User user; }; +TR_INSTANCE_INIT(Session); #endif // __SESSION_H__ diff --git a/include/storage/storage.h b/include/storage/storage.h index 403985a..6451c56 100644 --- a/include/storage/storage.h +++ b/include/storage/storage.h @@ -41,6 +41,7 @@ TR_CLASS(Storage) { GDBM_FILE gdbm; char * db_name; }; +TR_INSTANCE_INIT(Storage); StoragePutResult storagePut(Storage, char *, size_t, char *, size_t); StoragePutResult storageUpdate(Storage, char *, size_t, char *, size_t); diff --git a/include/user.h b/include/user.h index 13c9221..3001227 100644 --- a/include/user.h +++ b/include/user.h @@ -53,6 +53,7 @@ TR_CLASS(User) { size_t * nfirstname; size_t * nsurname; }; +TR_INSTANCE_INIT(User); #endif // __USER_H__ diff --git a/src/server/handle_accept.c b/src/server/handle_accept.c index a4bc2e8..aecdbc7 100644 --- a/src/server/handle_accept.c +++ b/src/server/handle_accept.c @@ -34,15 +34,16 @@ int serverHandleAccept(Server this, unsigned int i) { - char remoteAddr[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; - TR_Sock acc = NULL; - TR_Stream st; + TR_Socket acc = NULL; + TR_Stream st; if (this->nfds >= this->max_fds) { return -1; } - acc = TR_socketAccept((0 == i)? this->sock : this->sockSSL, &remoteAddr); + acc = (TR_Socket)TR_socketAccept((0 == i) + ? (TR_TcpSocket)this->sock + : (TR_TcpSocket)this->sockSSL); if (NULL != acc && -1 != acc->handle) { TR_socketNonblock(acc); diff --git a/src/server/server.c b/src/server/server.c index b8a3a9b..aaf8a2d 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -65,11 +65,13 @@ serverCtor(void * _this, va_list * params) this->fds = TR_calloc(sizeof(struct pollfd), this->max_fds); this->conns = TR_calloc(sizeof(struct conns), this->max_fds); - this->sock = TR_new(TR_Sock, this->logger, port); + this->sock = TR_new(TR_TcpSocket, this->logger, "0.0.0.0", port, 0); TR_socketNonblock(this->sock); + TR_socketBind((TR_Socket)this->sock); - this->sockSSL = TR_new(TR_Sock, this->logger, port+1); + this->sockSSL = TR_new(TR_TcpSocket, this->logger, "0.0.0.0", port+1, 0); TR_socketNonblock(this->sockSSL); + TR_socketBind((TR_Socket)this->sockSSL); SSL_library_init(); OpenSSL_add_all_algorithms(); @@ -88,9 +90,6 @@ serverCtor(void * _this, va_list * params) CONFIGDIR "/taskrambler.pem", SSL_FILETYPE_PEM); - TR_socketListen(this->sock, backlog); - TR_socketListen(this->sockSSL, backlog); - (this->fds)[0].fd = this->sock->handle; (this->fds)[0].events = POLLIN; (this->fds)[1].fd = this->sockSSL->handle;