xref: /lighttpd1.4/src/mod_vhostdb_api.c (revision 0fd89187)
1 /*
2  * http_vhostdb_api - virtual hosts mapping backend registration
3  *
4  * Copyright(c) 2017 Glenn Strauss gstrauss()gluelogic.com  All rights reserved
5  * License: BSD 3-clause (same as lighttpd)
6  */
7 #include "first.h"
8 
9 #include "mod_vhostdb_api.h"
10 
11 #include <string.h>
12 
13 
14 static http_vhostdb_backend_t http_vhostdb_backends[8];
15 
http_vhostdb_dumbdata_reset(void)16 void http_vhostdb_dumbdata_reset (void)
17 {
18     memset(http_vhostdb_backends, 0, sizeof(http_vhostdb_backends));
19 }
20 
http_vhostdb_backend_get(const buffer * name)21 const http_vhostdb_backend_t * http_vhostdb_backend_get (const buffer *name)
22 {
23     int i = 0;
24     while (NULL != http_vhostdb_backends[i].name
25            && 0 != strcmp(http_vhostdb_backends[i].name, name->ptr)) {
26         ++i;
27     }
28     return (NULL != http_vhostdb_backends[i].name)
29       ? http_vhostdb_backends+i
30       : NULL;
31 }
32 
http_vhostdb_backend_set(const http_vhostdb_backend_t * backend)33 void http_vhostdb_backend_set (const http_vhostdb_backend_t *backend)
34 {
35     unsigned int i = 0;
36     while (NULL != http_vhostdb_backends[i].name) ++i;
37     /*(must resize http_vhostdb_backends[] if too many different backends)*/
38     force_assert(
39       i < (sizeof(http_vhostdb_backends)/sizeof(http_vhostdb_backend_t))-1);
40     memcpy(http_vhostdb_backends+i, backend, sizeof(http_vhostdb_backend_t));
41 }
42