--- 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;