Changeset 432
- Timestamp:
- 07/09/2005 08:17:07 PM (3 years ago)
- Location:
- branches/lighttpd-1.3.x/src
- Files:
-
- 5 modified
-
Makefile.am (modified) (1 diff)
-
mod_cml.c (modified) (4 diffs)
-
mod_cml.h (modified) (3 diffs)
-
mod_cml_funcs.c (modified) (3 diffs)
-
mod_cml_logic.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/lighttpd-1.3.x/src/Makefile.am
r429 r432 72 72 mod_cml_la_SOURCES = mod_cml.c mod_cml_funcs.c mod_cml_logic.c 73 73 mod_cml_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined 74 mod_cml_la_LIBADD = $(M YSQL_LIBS) $(common_libadd)74 mod_cml_la_LIBADD = $(MEMCACHE_LIB) $(common_libadd) 75 75 76 76 lib_LTLIBRARIES += mod_trigger_b4_dl.la -
branches/lighttpd-1.3.x/src/mod_cml.c
r428 r432 51 51 buffer_free(s->ext); 52 52 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 53 60 free(s); 54 61 } … … 78 85 79 86 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 */ 81 90 { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } 82 91 }; … … 91 100 s = malloc(sizeof(plugin_config)); 92 101 s->ext = buffer_init(); 102 s->mc_hosts = array_init(); 103 s->mc_namespace = buffer_init(); 93 104 94 105 cv[0].destination = s->ext; 106 cv[1].destination = s->mc_hosts; 107 cv[2].destination = s->mc_namespace; 95 108 96 109 p->config_storage[i] = s; … … 98 111 if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) { 99 112 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 100 136 } 101 137 } -
branches/lighttpd-1.3.x/src/mod_cml.h
r431 r432 7 7 8 8 #include "stream.h" 9 10 #if defined(HAVE_MEMCACHE_H) 11 #include <memcache.h> 12 #endif 9 13 10 14 #define plugin_data mod_cache_plugin_data … … 46 50 buffer *ext; 47 51 52 array *mc_hosts; 53 buffer *mc_namespace; 54 #if defined(HAVE_MEMCACHE_H) 55 struct memcache *mc; 56 #endif 48 57 } plugin_config; 49 58 … … 87 96 CACHE_FUNC_PROTO(f_unix_time_now); 88 97 CACHE_FUNC_PROTO(f_file_mtime); 89 CACHE_FUNC_PROTO(f_memcache_get);90 98 CACHE_FUNC_PROTO(f_memcache_exists); 99 CACHE_FUNC_PROTO(f_memcache_get_string); 100 CACHE_FUNC_PROTO(f_memcache_get_long); 91 101 92 102 #endif -
branches/lighttpd-1.3.x/src/mod_cml_funcs.c
r431 r432 62 62 } 63 63 64 #ifdef HAVE_MEMCACHE_H 64 65 CACHE_FUNC_PROTO(f_memcache_exists) { 65 UNUSED(srv); 66 char *r; 67 66 68 UNUSED(con); 67 69 … … 75 77 76 78 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; 78 90 79 91 return 0; 80 92 } 81 93 82 CACHE_FUNC_PROTO(f_memcache_get) { 83 UNUSED(srv); 94 CACHE_FUNC_PROTO(f_memcache_get_string) { 95 char *r; 96 84 97 UNUSED(con); 85 98 … … 91 104 } 92 105 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 } 93 117 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); 95 121 96 122 return 0; 97 123 } 124 125 CACHE_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 166 166 { "file.mtime", 1, f_file_mtime }, 167 167 { "unix.time.now", 0, f_unix_time_now }, 168 #ifdef HAVE_MEMCACHE_H 168 169 { "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 170 173 { NULL, 0, NULL }, 171 174 }; … … 481 484 } else if (IS_STRING(t->l) && IS_STRING(t->r)) { 482 485 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"); 484 488 return -1; 485 489 } 486 490 } else { 487 fprintf(stderr, "%s.%d: typemismatch\n",488 __FILE__, __LINE__);491 log_error_write(srv, __FILE__, __LINE__, "s", 492 "typemismatch"); 489 493 490 494 return -1; … … 506 510 507 511 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"); 509 514 return -1; 510 515 }

