aboutsummaryrefslogtreecommitdiff
path: root/src/variable.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-15 14:20:42 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-01-15 14:20:42 +0200
commit746f6355a4595cc4bbcffc89a3e42a082d757759 (patch)
tree8530127396a94f3d70bdef83a0aaffddb1b80469 /src/variable.c
parent5fc59f5271d5ca06374782848bcd53adecfffcf1 (diff)
downloadvmod-variable-746f6355a4595cc4bbcffc89a3e42a082d757759.tar.gz
vmod-variable-746f6355a4595cc4bbcffc89a3e42a082d757759.tar.bz2
Revert "Store per-session symtabs in private storage."
This reverts commit 5fc59f5271d5ca06374782848bcd53adecfffcf1, which in fact pertains to 4.1 branch.
Diffstat (limited to 'src/variable.c')
-rw-r--r--src/variable.c91
1 files changed, 48 insertions, 43 deletions
diff --git a/src/variable.c b/src/variable.c
index acdc6f6..bd79c3b 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -310,6 +310,10 @@ symtab_free(struct symtab *st)
310} 310}
311 311
312 312
313static struct symtab **symtabv;
314static size_t symtabc;
315static pthread_mutex_t symtab_mtx = PTHREAD_MUTEX_INITIALIZER;
316
313static struct symtab *global_symtab; 317static struct symtab *global_symtab;
314static pthread_mutex_t global_mtx = PTHREAD_MUTEX_INITIALIZER; 318static pthread_mutex_t global_mtx = PTHREAD_MUTEX_INITIALIZER;
315 319
@@ -377,20 +381,26 @@ vmod_global_unset(VARIABLE_CTX ctx, VCL_STRING name)
377 AZ(pthread_mutex_unlock(&global_mtx)); 381 AZ(pthread_mutex_unlock(&global_mtx));
378} 382}
379 383
380static void
381priv_symtab_free(void *p)
382{
383 symtab_free(p);
384}
385
386static struct symtab * 384static struct symtab *
387get_symtab(struct vmod_priv *priv) 385get_symtab(VARIABLE_CTX ctx)
388{ 386{
389 if (!priv->priv) { 387 struct symtab *st;
390 priv->priv = symtab_create(); 388 int fd = ctx->req->sp->fd;
391 priv->free = priv_symtab_free; 389 AZ(pthread_mutex_lock(&symtab_mtx));
392 } 390 if (symtabc <= fd) {
393 return priv->priv; 391 size_t n = fd + 1;
392 symtabv = realloc(symtabv, n * sizeof(symtabv[0]));
393 while (symtabc < n)
394 symtabv[symtabc++] = NULL;
395 }
396 if (!symtabv[fd])
397 symtabv[fd] = symtab_create();
398 st = symtabv[fd];
399 if (st->vxid != ctx->req->sp->vxid)
400 symtab_clear(st);
401 st->vxid = ctx->req->sp->vxid;
402 AZ(pthread_mutex_unlock(&symtab_mtx));
403 return st;
394} 404}
395 405
396#define getvar(vt, name) symtab_lookup_or_install(vt, name, NULL) 406#define getvar(vt, name) symtab_lookup_or_install(vt, name, NULL)
@@ -412,25 +422,24 @@ defvar(struct symtab *vt, const char *name, enum variable_type t,
412} 422}
413 423
414VCL_VOID 424VCL_VOID
415vmod_clear(VARIABLE_CTX ctx, struct vmod_priv *priv) 425vmod_clear(VARIABLE_CTX ctx)
416{ 426{
417 symtab_clear(get_symtab(priv)); 427 symtab_clear(get_symtab(ctx));
418} 428}
419 429
420VCL_STRING 430VCL_STRING
421vmod_get_string(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name) 431vmod_get_string(VARIABLE_CTX ctx, VCL_STRING name)
422{ 432{
423 struct variable *var = getvar(get_symtab(priv), name); 433 struct variable *var = getvar(get_symtab(ctx), name);
424 if (var && var->type == variable_string) 434 if (var && var->type == variable_string)
425 return var->v.s; 435 return var->v.s;
426 return NULL; 436 return NULL;
427} 437}
428 438
429VCL_VOID 439VCL_VOID
430vmod_set_string(VARIABLE_CTX ctx, struct vmod_priv *priv, 440vmod_set_string(VARIABLE_CTX ctx, VCL_STRING name, VCL_STRING value)
431 VCL_STRING name, VCL_STRING value)
432{ 441{
433 struct symtab *vt = get_symtab(priv); 442 struct symtab *vt = get_symtab(ctx);
434 struct variable *var = defvar(vt, name, variable_unset, NULL); 443 struct variable *var = defvar(vt, name, variable_unset, NULL);
435 var->type = variable_string; 444 var->type = variable_string;
436 var->v.s = strdup(value ? value : ""); 445 var->v.s = strdup(value ? value : "");
@@ -438,25 +447,23 @@ vmod_set_string(VARIABLE_CTX ctx, struct vmod_priv *priv,
438} 447}
439 448
440VCL_STRING 449VCL_STRING
441vmod_get(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name) 450vmod_get(VARIABLE_CTX ctx, VCL_STRING name)
442{ 451{
443 return vmod_get_string(ctx, priv, name); 452 return vmod_get_string(ctx, name);
444} 453}
445 454
446VCL_VOID 455VCL_VOID
447vmod_set(VARIABLE_CTX ctx, struct vmod_priv *priv, 456vmod_set(VARIABLE_CTX ctx, VCL_STRING name, VCL_STRING value)
448 VCL_STRING name, VCL_STRING value)
449{ 457{
450 vmod_set_string(ctx, priv, name, value); 458 vmod_set_string(ctx, name, value);
451} 459}
452 460
453#define __cat__(a,b) a ## b 461#define __cat__(a,b) a ## b
454#define DEFGET(r_type, vcl_type, memb) \ 462#define DEFGET(r_type, vcl_type, memb) \
455vcl_type \ 463vcl_type \
456__cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, struct vmod_priv *priv, \ 464__cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, VCL_STRING name) \
457 VCL_STRING name) \
458{ \ 465{ \
459 struct variable *var = getvar(get_symtab(priv), name); \ 466 struct variable *var = getvar(get_symtab(ctx), name); \
460 if (var && var->type == __cat__(variable_,r_type)) \ 467 if (var && var->type == __cat__(variable_,r_type)) \
461 return var->v.memb; \ 468 return var->v.memb; \
462 return 0; \ 469 return 0; \
@@ -464,11 +471,10 @@ __cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, struct vmod_priv *priv, \
464 471
465#define DEFSET(r_type, vcl_type, memb) \ 472#define DEFSET(r_type, vcl_type, memb) \
466VCL_VOID \ 473VCL_VOID \
467__cat__(vmod_set_,r_type)(VARIABLE_CTX ctx, struct vmod_priv *priv, \ 474__cat__(vmod_set_,r_type)(VARIABLE_CTX ctx, VCL_STRING name, \
468 VCL_STRING name, \
469 vcl_type value) \ 475 vcl_type value) \
470{ \ 476{ \
471 struct symtab *vt = get_symtab(priv); \ 477 struct symtab *vt = get_symtab(ctx); \
472 struct variable *var = defvar(vt, name, variable_unset, NULL); \ 478 struct variable *var = defvar(vt, name, variable_unset, NULL); \
473 var->type = __cat__(variable_,r_type); \ 479 var->type = __cat__(variable_,r_type); \
474 var->v.memb = value; \ 480 var->v.memb = value; \
@@ -483,22 +489,22 @@ DEF(real, VCL_REAL, r)
483DEF(duration, VCL_DURATION, d) 489DEF(duration, VCL_DURATION, d)
484 490
485VCL_BOOL 491VCL_BOOL
486vmod_defined(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name) 492vmod_defined(VARIABLE_CTX ctx, VCL_STRING name)
487{ 493{
488 return !!getvar(get_symtab(priv), name); 494 return !!getvar(get_symtab(ctx), name);
489} 495}
490 496
491VCL_STRING 497VCL_STRING
492vmod_type_of(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name) 498vmod_type_of(VARIABLE_CTX ctx, VCL_STRING name)
493{ 499{
494 struct variable *var = getvar(get_symtab(priv), name); 500 struct variable *var = getvar(get_symtab(ctx), name);
495 return typestr[var ? var->type : variable_unset]; 501 return typestr[var ? var->type : variable_unset];
496} 502}
497 503
498VCL_VOID 504VCL_VOID
499vmod_unset(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name) 505vmod_unset(VARIABLE_CTX ctx, VCL_STRING name)
500{ 506{
501 symtab_remove(get_symtab(priv), name); 507 symtab_remove(get_symtab(ctx), name);
502} 508}
503 509
504static void 510static void
@@ -710,10 +716,10 @@ setval(union value *val, const char *s, enum variable_type type, char **err)
710} 716}
711 717
712VCL_VOID 718VCL_VOID
713vmod_regset(VARIABLE_CTX ctx, struct vmod_priv *priv, 719vmod_regset(VARIABLE_CTX ctx, VCL_STRING vars, VCL_STRING rxs,
714 VCL_STRING vars, VCL_STRING rxs, VCL_STRING input) 720 VCL_STRING input)
715{ 721{
716 struct symtab *vt = get_symtab(priv); 722 struct symtab *vt = get_symtab(ctx);
717 struct vardef *head = NULL, *tail = NULL, *def; 723 struct vardef *head = NULL, *tail = NULL, *def;
718 size_t count = 0; 724 size_t count = 0;
719 size_t n; 725 size_t n;
@@ -887,10 +893,9 @@ define_param(struct symtab *vt, struct vardef *def,
887} 893}
888 894
889VCL_VOID 895VCL_VOID
890vmod_queryset(VARIABLE_CTX ctx, struct vmod_priv *priv, 896vmod_queryset(VARIABLE_CTX ctx, VCL_STRING vars, VCL_STRING query)
891 VCL_STRING vars, VCL_STRING query)
892{ 897{
893 struct symtab *vt = get_symtab(priv); 898 struct symtab *vt = get_symtab(ctx);
894 struct vardef *head = NULL, *tail = NULL, *def; 899 struct vardef *head = NULL, *tail = NULL, *def;
895 size_t count = 0; 900 size_t count = 0;
896 size_t n; 901 size_t n;

Return to:

Send suggestions and report system problems to the System administrator.