Skip to content

Commit

Permalink
tweak: shdict.c: removed unused 'ngx_http_lua_shared_dict_get' CFunct…
Browse files Browse the repository at this point in the history
…ion API.
  • Loading branch information
thibaultcha committed Aug 27, 2019
1 parent 315330a commit a79e9aa
Showing 1 changed file with 0 additions and 103 deletions.
103 changes: 0 additions & 103 deletions src/ngx_http_lua_shdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,109 +582,6 @@ ngx_http_lua_shdict_get_keys(lua_State *L)
}


ngx_int_t
ngx_http_lua_shared_dict_get(ngx_shm_zone_t *zone, u_char *key_data,
size_t key_len, ngx_http_lua_value_t *value)
{
u_char *data;
size_t len;
uint32_t hash;
ngx_int_t rc;
ngx_http_lua_shdict_ctx_t *ctx;
ngx_http_lua_shdict_node_t *sd;

if (zone == NULL) {
return NGX_ERROR;
}

hash = ngx_crc32_short(key_data, key_len);

ctx = zone->data;

ngx_shmtx_lock(&ctx->shpool->mutex);

rc = ngx_http_lua_shdict_lookup(zone, hash, key_data, key_len, &sd);

dd("shdict lookup returned %d", (int) rc);

if (rc == NGX_DECLINED || rc == NGX_DONE) {
ngx_shmtx_unlock(&ctx->shpool->mutex);

return rc;
}

/* rc == NGX_OK */

value->type = sd->value_type;

dd("type: %d", (int) value->type);

data = sd->data + sd->key_len;
len = (size_t) sd->value_len;

switch (value->type) {

case SHDICT_TSTRING:

if (value->value.s.data == NULL || value->value.s.len == 0) {
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0, "no string buffer "
"initialized");
ngx_shmtx_unlock(&ctx->shpool->mutex);
return NGX_ERROR;
}

if (len > value->value.s.len) {
len = value->value.s.len;

} else {
value->value.s.len = len;
}

ngx_memcpy(value->value.s.data, data, len);
break;

case SHDICT_TNUMBER:

if (len != sizeof(double)) {
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0, "bad lua number "
"value size found for key %*s: %lu", key_len,
key_data, (unsigned long) len);

ngx_shmtx_unlock(&ctx->shpool->mutex);
return NGX_ERROR;
}

ngx_memcpy(&value->value.b, data, len);
break;

case SHDICT_TBOOLEAN:

if (len != sizeof(u_char)) {
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0, "bad lua boolean "
"value size found for key %*s: %lu", key_len,
key_data, (unsigned long) len);

ngx_shmtx_unlock(&ctx->shpool->mutex);
return NGX_ERROR;
}

value->value.b = *data;
break;

default:
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0, "bad lua value type "
"found for key %*s: %d", key_len, key_data,
(int) value->type);

ngx_shmtx_unlock(&ctx->shpool->mutex);
return NGX_ERROR;
}

ngx_shmtx_unlock(&ctx->shpool->mutex);
return NGX_OK;
}


static int
ngx_http_lua_shdict_lpush(lua_State *L)
{
Expand Down

0 comments on commit a79e9aa

Please sign in to comment.