Changeset 432

Show
Ignore:
Timestamp:
07/09/2005 08:17:07 PM (3 years ago)
Author:
jan
Message:

added memcache support

Location:
branches/lighttpd-1.3.x/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • branches/lighttpd-1.3.x/src/Makefile.am

    r429 r432  
    7272mod_cml_la_SOURCES = mod_cml.c mod_cml_funcs.c mod_cml_logic.c 
    7373mod_cml_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined 
    74 mod_cml_la_LIBADD = $(MYSQL_LIBS) $(common_libadd) 
     74mod_cml_la_LIBADD = $(MEMCACHE_LIB) $(common_libadd) 
    7575 
    7676lib_LTLIBRARIES += mod_trigger_b4_dl.la 
  • branches/lighttpd-1.3.x/src/mod_cml.c

    r428 r432  
    5151                        buffer_free(s->ext); 
    5252                         
     53                        buffer_free(s->mc_namespace); 
     54                        array_free(s->mc_hosts); 
     55                         
     56#if defined(HAVE_MEMCACHE_H) 
     57                        if (s->mc) mc_free(s->mc); 
     58#endif 
     59                         
    5360                        free(s); 
    5461                } 
     
    7885         
    7986        config_values_t cv[] = {  
    80                 { "cml.extension",            NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },       /* 0 */ 
     87                { "cml.extension",              NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },       /* 0 */ 
     88                { "cml.memcache-hosts",         NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },        /* 1 */ 
     89                { "cml.memcache-namespace",     NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },       /* 2 */ 
    8190                { NULL,                         NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } 
    8291        }; 
     
    91100                s = malloc(sizeof(plugin_config)); 
    92101                s->ext    = buffer_init(); 
     102                s->mc_hosts       = array_init(); 
     103                s->mc_namespace   = buffer_init(); 
    93104                 
    94105                cv[0].destination = s->ext; 
     106                cv[1].destination = s->mc_hosts; 
     107                cv[2].destination = s->mc_namespace; 
    95108                 
    96109                p->config_storage[i] = s; 
     
    98111                if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) { 
    99112                        return HANDLER_ERROR; 
     113                } 
     114                 
     115                if (s->mc_hosts->used) { 
     116#if defined(HAVE_MEMCACHE_H) 
     117                        size_t k; 
     118                        s->mc = mc_new(); 
     119                 
     120                        for (k = 0; k < s->mc_hosts->used; k++) { 
     121                                data_string *ds = (data_string *)s->mc_hosts->data[k]; 
     122                                 
     123                                if (0 != mc_server_add4(s->mc, ds->value->ptr)) { 
     124                                        log_error_write(srv, __FILE__, __LINE__, "sb",  
     125                                                        "connection to host failed:",  
     126                                                        ds->value); 
     127                                         
     128                                        return HANDLER_ERROR; 
     129                                } 
     130                        } 
     131#else 
     132                        log_error_write(srv, __FILE__, __LINE__, "s",  
     133                                        "memcache support is not compiled in but cml.memcache-hosts is set, aborting"); 
     134                        return HANDLER_ERROR; 
     135#endif 
    100136                } 
    101137        } 
  • branches/lighttpd-1.3.x/src/mod_cml.h

    r431 r432  
    77 
    88#include "stream.h" 
     9 
     10#if defined(HAVE_MEMCACHE_H) 
     11#include <memcache.h> 
     12#endif 
    913 
    1014#define plugin_data mod_cache_plugin_data 
     
    4650        buffer *ext; 
    4751         
     52        array  *mc_hosts; 
     53        buffer *mc_namespace; 
     54#if defined(HAVE_MEMCACHE_H)  
     55        struct memcache *mc; 
     56#endif 
    4857} plugin_config; 
    4958 
     
    8796CACHE_FUNC_PROTO(f_unix_time_now); 
    8897CACHE_FUNC_PROTO(f_file_mtime); 
    89 CACHE_FUNC_PROTO(f_memcache_get); 
    9098CACHE_FUNC_PROTO(f_memcache_exists); 
     99CACHE_FUNC_PROTO(f_memcache_get_string); 
     100CACHE_FUNC_PROTO(f_memcache_get_long); 
    91101 
    92102#endif 
  • branches/lighttpd-1.3.x/src/mod_cml_funcs.c

    r431 r432  
    6262} 
    6363 
     64#ifdef HAVE_MEMCACHE_H 
    6465CACHE_FUNC_PROTO(f_memcache_exists) { 
    65         UNUSED(srv); 
     66        char *r; 
     67         
    6668        UNUSED(con); 
    6769         
     
    7577         
    7678        tnode_prepare_long(result); 
    77         VAL_LONG(result) = 0; 
     79         
     80        if (NULL == (r = mc_aget(p->conf.mc,  
     81                                 CONST_BUF_LEN(p->params->ptr[0]->data.str)))) { 
     82                                 
     83                VAL_LONG(result) = 0; 
     84                return 0; 
     85        } 
     86         
     87        free(r); 
     88         
     89        VAL_LONG(result) = 1; 
    7890         
    7991        return 0; 
    8092} 
    8193 
    82 CACHE_FUNC_PROTO(f_memcache_get) { 
    83         UNUSED(srv); 
     94CACHE_FUNC_PROTO(f_memcache_get_string) { 
     95        char *r; 
     96         
    8497        UNUSED(con); 
    8598         
     
    91104        } 
    92105         
     106        log_error_write(srv, __FILE__, __LINE__, "sb",  
     107                                "f_memcache_get: couldn't find:",  
     108                                p->params->ptr[0]->data.str); 
     109         
     110        if (NULL == (r = mc_aget(p->conf.mc,  
     111                                p->params->ptr[0]->data.str->ptr, p->params->ptr[0]->data.str->used - 1))) { 
     112                log_error_write(srv, __FILE__, __LINE__, "sb",  
     113                                "f_memcache_get: couldn't find:",  
     114                                p->params->ptr[0]->data.str); 
     115                return -1; 
     116        } 
    93117        tnode_prepare_string(result); 
    94         buffer_copy_string_buffer(VAL_STRING(result), p->params->ptr[0]->data.str); 
     118        buffer_copy_string(VAL_STRING(result), r); 
     119         
     120        free(r); 
    95121         
    96122        return 0; 
    97123} 
     124 
     125CACHE_FUNC_PROTO(f_memcache_get_long) { 
     126        char *r; 
     127         
     128        UNUSED(con); 
     129         
     130        if (p->params->ptr[0]->type != T_NODE_VALUE_STRING) { 
     131                log_error_write(srv, __FILE__, __LINE__, "sd",  
     132                                "f_memcache_get: I need a string:",  
     133                                p->params->ptr[0]->type); 
     134                return -1; 
     135        } 
     136         
     137         
     138         
     139        if (NULL == (r = mc_aget(p->conf.mc,  
     140                                 CONST_BUF_LEN(p->params->ptr[0]->data.str)))) { 
     141                log_error_write(srv, __FILE__, __LINE__, "sb",  
     142                                "f_memcache_get: couldn't find:",  
     143                                p->params->ptr[0]->data.str); 
     144                return -1; 
     145        } 
     146         
     147        tnode_prepare_long(result); 
     148        VAL_LONG(result) = strtol(r, NULL, 10); 
     149         
     150        free(r); 
     151         
     152        return 0; 
     153} 
     154#endif 
  • branches/lighttpd-1.3.x/src/mod_cml_logic.c

    r431 r432  
    166166                { "file.mtime",     1, f_file_mtime }, 
    167167                { "unix.time.now",  0, f_unix_time_now }, 
     168#ifdef HAVE_MEMCACHE_H 
    168169                { "memcache.exits", 1, f_memcache_exists }, 
    169                 { "memcache.get",   1, f_memcache_get }, 
     170                { "memcache.get_string",   1, f_memcache_get_string }, 
     171                { "memcache.get_long",     1, f_memcache_get_long }, 
     172#endif 
    170173                { NULL, 0, NULL }, 
    171174        }; 
     
    481484        } else if (IS_STRING(t->l) && IS_STRING(t->r)) { 
    482485                if (-1 == cache_ops_string(t, t->l, t->r)) { 
    483                         fprintf(stderr, "%s.%d: cache_ops_string failed\n", __FILE__, __LINE__); 
     486                        log_error_write(srv, __FILE__, __LINE__, "s",  
     487                                        "cache_ops_string failed"); 
    484488                        return -1; 
    485489                } 
    486490        } else { 
    487                 fprintf(stderr, "%s.%d: typemismatch\n", 
    488                         __FILE__, __LINE__); 
     491                log_error_write(srv, __FILE__, __LINE__, "s",  
     492                                "typemismatch"); 
    489493                 
    490494                return -1; 
     
    506510                 
    507511                if (-1 == cache_trigger_eval(srv, con, p, t)) { 
    508                         fprintf(stderr, "%s.%d: cache_trigger_eval failed\n", __FILE__, __LINE__); 
     512                        log_error_write(srv, __FILE__, __LINE__, "s",  
     513                                        "cache_trigger_eval failed"); 
    509514                        return -1; 
    510515                }