@@ -33,9 +33,22 @@ VCL_VOID
3333vmod_init_db (VRT_CTX , struct vmod_priv * priv , char * filename , char * memtype )
3434{
3535 IP2Proxy * IP2ProxyObj ;
36+ enum IP2Proxy_mem_type mtype ;
3637
3738 CHECK_OBJ_NOTNULL (ctx , VRT_CTX_MAGIC );
3839 AN (priv );
40+ AN (memtype );
41+
42+ if (strcmp (memtype , "IP2PROXY_FILE_IO" ) == 0 )
43+ mtype = IP2PROXY_FILE_IO ;
44+ else if (strcmp (memtype , "IP2PROXY_SHARED_MEMORY" ) == 0 )
45+ mtype = IP2PROXY_SHARED_MEMORY ;
46+ else if (strcmp (memtype , "IP2PROXY_CACHE_MEMORY" ) == 0 )
47+ mtype = IP2PROXY_CACHE_MEMORY ;
48+ else {
49+ VRT_fail (ctx , "IP2Proxy: invalid memtype (%s)" , memtype );
50+ return ;
51+ }
3952
4053 if (priv -> priv != NULL )
4154 IP2Proxy_close ((IP2Proxy * )priv -> priv );
@@ -45,13 +58,7 @@ vmod_init_db(VRT_CTX, struct vmod_priv *priv, char *filename, char *memtype)
4558 VRT_fail (ctx , "IP2Proxy: can't open database (%s)" , filename );
4659 return ;
4760 }
48-
49- if (strcmp (memtype , "IP2PROXY_FILE_IO" ) == 0 )
50- IP2Proxy_open_mem (IP2ProxyObj , IP2PROXY_FILE_IO );
51- else if (strcmp (memtype , "IP2PROXY_SHARED_MEMORY" ) == 0 )
52- IP2Proxy_open_mem (IP2ProxyObj , IP2PROXY_SHARED_MEMORY );
53- else if (strcmp (memtype , "IP2PROXY_CACHE_MEMORY" ) == 0 )
54- IP2Proxy_open_mem (IP2ProxyObj , IP2PROXY_CACHE_MEMORY );
61+ IP2Proxy_open_mem (IP2ProxyObj , mtype );
5562
5663 priv -> priv = IP2ProxyObj ;
5764 priv -> free = ip2proxy_free ;
0 commit comments