Fri, 05 Dec 2025 17:37:48 +0100
add session_create
--- a/src/server/daemon/httprequest.c Tue Dec 02 19:35:29 2025 +0100 +++ b/src/server/daemon/httprequest.c Fri Dec 05 17:37:48 2025 +0100 @@ -87,47 +87,6 @@ return (cxmutstr){ "/", 1 }; } -NSAPISession* nsapisession_create(pool_handle_t *pool) { - NSAPISession *sn = pool_malloc(pool, sizeof(NSAPISession)); - if(!sn) { - return NULL; - } - - ZERO(sn, sizeof(NSAPISession)); - - sn->sn.pool = pool; - - sn->sn.client = pblock_create_pool(sn->sn.pool, 8); - if(!sn->sn.client) { - pool_free(pool, sn); - return NULL; - } - sn->sn.fill = 1; - - return sn; -} - -int nsapisession_setconnection(NSAPISession *sn, Connection *conn, netbuf *inbuf, IOStream **io) { - SessionHandler *sh = conn->session_handler; - WSBool ssl; - IOStream *sio = sh->create_iostream(sh, conn, sn->sn.pool, &ssl); - if(!sio) { - return 1; - } - *io = sio; - IOStream *http = httpstream_new(sn->sn.pool, sio); - if(!http) { - return 1; - } - sn->connection = conn; - sn->netbuf = inbuf; - sn->sn.csd = http; - sn->sn.ssl = ssl; - sn->sn.inbuf = inbuf; - sn->sn.inbuf->sd = http; - return 0; -} - int handle_request(HTTPRequest *request, threadpool_t *thrpool, EventHandler *ev) { // handle nsapi request
--- a/src/server/daemon/httprequest.h Tue Dec 02 19:35:29 2025 +0100 +++ b/src/server/daemon/httprequest.h Fri Dec 05 17:37:48 2025 +0100 @@ -75,9 +75,6 @@ cxmutstr http_request_get_abspath(HTTPRequest *req); -NSAPISession* nsapisession_create(pool_handle_t *pool); -int nsapisession_setconnection(NSAPISession *sn, Connection *conn, netbuf *inbuf, IOStream **io); - /* * starts request processing after reading the request header *
--- a/src/server/daemon/session.c Tue Dec 02 19:35:29 2025 +0100 +++ b/src/server/daemon/session.c Fri Dec 05 17:37:48 2025 +0100 @@ -30,6 +30,88 @@ #include "session.h" +NSAPISession* nsapisession_create(pool_handle_t *pool) { + NSAPISession *sn = pool_malloc(pool, sizeof(NSAPISession)); + if(!sn) { + return NULL; + } + + ZERO(sn, sizeof(NSAPISession)); + + sn->sn.pool = pool; + + sn->sn.client = pblock_create_pool(sn->sn.pool, 8); + if(!sn->sn.client) { + pool_free(pool, sn); + return NULL; + } + sn->sn.fill = 1; + + return sn; +} + +int nsapisession_setconnection(NSAPISession *sn, Connection *conn, netbuf *inbuf, IOStream **io) { + SessionHandler *sh = conn->session_handler; + WSBool ssl; + IOStream *sio = sh->create_iostream(sh, conn, sn->sn.pool, &ssl); + if(!sio) { + return 1; + } + *io = sio; + IOStream *http = httpstream_new(sn->sn.pool, sio); + if(!http) { + return 1; + } + sn->connection = conn; + sn->netbuf = inbuf; + sn->sn.csd = http; + sn->sn.ssl = ssl; + sn->sn.inbuf = inbuf; + sn->sn.inbuf->sd = http; + return 0; +} + +int nsapisession_set_stream(NSAPISession *sn, SYS_NETFD csd) { + IOStream *http = httpstream_new(sn->sn.pool, csd); + if(!http) { + return 1; + } + netbuf *inbuf = netbuf_open(csd, 1024); + if(!inbuf) { + return 1; + } + sn->sn.csd = http; + sn->sn.inbuf = inbuf; + sn->netbuf = inbuf; + return 0; +} + +NSAPI_PUBLIC Session *session_create(SYS_NETFD csd, struct sockaddr_in *sac) { + pool_handle_t *pool = pool_create(); + if(!pool) { + return NULL; + } + + NSAPISession *sn = nsapisession_create(pool); + if(!sn) { + pool_destroy(pool); + return NULL; + } + + if(nsapisession_set_stream(sn, csd)) { + pool_destroy(pool); + return NULL; + } + + sn->sn.iaddr = sac->sin_addr; + sn->sn.csd_open = 1; + sn->sn.fill = 0; + sn->sn.ssl = 0; + sn->sn.clientauth = 0; + + return (Session*)sn; +} + NSAPI_PUBLIC char *session_dns_lookup(Session *s, int verify) { // TODO: implement return NULL;
--- a/src/server/daemon/session.h Tue Dec 02 19:35:29 2025 +0100 +++ b/src/server/daemon/session.h Fri Dec 05 17:37:48 2025 +0100 @@ -54,6 +54,14 @@ ServerConfiguration *config; }; +typedef struct IOStreamConnection { + +} IOStreamConnection; + +NSAPISession* nsapisession_create(pool_handle_t *pool); +int nsapisession_setconnection(NSAPISession *sn, Connection *conn, netbuf *inbuf, IOStream **io); +int nsapisession_set_stream(NSAPISession *sn, SYS_NETFD csd); + NSAPI_PUBLIC char *session_dns_lookup(Session *s, int verify); /* new functions */