# HG changeset patch
# User Olaf Wintermann <olaf.wintermann@gmail.com>
# Date 1660242073 -7200
# Node ID ea836c4f73413918c78f4adc768ef34b7ec35c8c
# Parent  d6d8c86c95c37a6377ebbcd7832210f2e45fee5a
add global resource lookup function

diff -r d6d8c86c95c3 -r ea836c4f7341 src/server/daemon/resourcepool.c
--- a/src/server/daemon/resourcepool.c	Wed Aug 10 21:01:54 2022 +0200
+++ b/src/server/daemon/resourcepool.c	Thu Aug 11 20:21:13 2022 +0200
@@ -114,11 +114,9 @@
     return 0;
 }
 
-ResourceData* resourcepool_lookup(Session *sn, Request *rq, const char *name, int flags) {
-    NSAPIRequest *request = (NSAPIRequest*)rq;
-    NSAPISession *session = (NSAPISession*)sn;
-    ServerConfiguration *cfg = session->config;
-    
+static ResourceData* s_resourcepool_lookup(ServerConfiguration *cfg, Request *opt_rq, Session *opt_sn, const char *name, int flags) {
+    NSAPIRequest *request = (NSAPIRequest*)opt_rq;
+    NSAPISession *session = (NSAPISession*)opt_sn;
     ResourceDataPrivate *resource = NULL;
     
     // was this resource already used by this request?
@@ -170,7 +168,7 @@
     // for cleanup later
     int err = 0;
     if(resource) {
-        if(request) {
+        if(request && session) {
             if(!request->resources) {
                 request->resources = ucx_map_new_a(&session->allocator, 8);
             }
@@ -202,6 +200,16 @@
     return (ResourceData*)resource;
 }
 
+ResourceData* resourcepool_cfg_lookup(ServerConfiguration *cfg, const char *name, int flags) {
+    return s_resourcepool_lookup(cfg, NULL, NULL, name, flags);
+}
+
+ResourceData* resourcepool_lookup(Session *sn, Request *rq, const char *name, int flags) {
+    NSAPISession *session = (NSAPISession*)sn;
+    ServerConfiguration *cfg = session->config;
+    return s_resourcepool_lookup(cfg, rq, sn, name, flags);
+}
+
 void resourcepool_free(Session *sn, Request *rq, ResourceData *resource) {
     ResourceDataPrivate *res = (ResourceDataPrivate*)resource;
     ResourcePool *respool = resource->resourcepool;
diff -r d6d8c86c95c3 -r ea836c4f7341 src/server/public/nsapi.h
--- a/src/server/public/nsapi.h	Wed Aug 10 21:01:54 2022 +0200
+++ b/src/server/public/nsapi.h	Thu Aug 11 20:21:13 2022 +0200
@@ -1621,6 +1621,7 @@
 
 // resource pool
 ResourceData* resourcepool_lookup(Session *sn, Request *rq, const char *name, int flags);
+ResourceData* resourcepool_cfg_lookup(ServerConfiguration *cfg, const char *name, int flags);
 void resourcepool_free(Session *sn, Request *rq, ResourceData *resource);
 
 // utils