Commit da8912c1 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Constify a lot of the VRT API


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2042 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 3398be57
...@@ -63,7 +63,7 @@ VRT_error(struct sess *sp, unsigned code, const char *reason) ...@@ -63,7 +63,7 @@ VRT_error(struct sess *sp, unsigned code, const char *reason)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
void void
VRT_count(struct sess *sp, unsigned u) VRT_count(const struct sess *sp, unsigned u)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
...@@ -101,7 +101,7 @@ vrt_selecthttp(const struct sess *sp, enum gethdr_e where) ...@@ -101,7 +101,7 @@ vrt_selecthttp(const struct sess *sp, enum gethdr_e where)
} }
char * char *
VRT_GetHdr(struct sess *sp, enum gethdr_e where, const char *n) VRT_GetHdr(const struct sess *sp, enum gethdr_e where, const char *n)
{ {
char *p; char *p;
struct http *hp; struct http *hp;
...@@ -155,7 +155,7 @@ vrt_assemble_string(struct http *hp, const char *h, const char *p, va_list ap) ...@@ -155,7 +155,7 @@ vrt_assemble_string(struct http *hp, const char *h, const char *p, va_list ap)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
void void
VRT_SetHdr(struct sess *sp , enum gethdr_e where, const char *hdr, const char *p, ...) VRT_SetHdr(const struct sess *sp , enum gethdr_e where, const char *hdr, const char *p, ...)
{ {
struct http *hp; struct http *hp;
va_list ap; va_list ap;
...@@ -198,7 +198,7 @@ vrt_do_string(struct worker *w, int fd, struct http *hp, int fld, const char *er ...@@ -198,7 +198,7 @@ vrt_do_string(struct worker *w, int fd, struct http *hp, int fld, const char *er
#define VRT_DO_HDR(obj, hdr, http, fld) \ #define VRT_DO_HDR(obj, hdr, http, fld) \
void \ void \
VRT_l_##obj##_##hdr(struct sess *sp, const char *p, ...) \ VRT_l_##obj##_##hdr(const struct sess *sp, const char *p, ...) \
{ \ { \
va_list ap; \ va_list ap; \
\ \
...@@ -221,7 +221,7 @@ VRT_DO_HDR(resp, proto, sp->http, HTTP_HDR_PROTO) ...@@ -221,7 +221,7 @@ VRT_DO_HDR(resp, proto, sp->http, HTTP_HDR_PROTO)
VRT_DO_HDR(resp, response, sp->http, HTTP_HDR_RESPONSE) VRT_DO_HDR(resp, response, sp->http, HTTP_HDR_RESPONSE)
void void
VRT_l_obj_status(struct sess *sp, int num) VRT_l_obj_status(const struct sess *sp, int num)
{ {
char *p; char *p;
...@@ -235,7 +235,7 @@ VRT_l_obj_status(struct sess *sp, int num) ...@@ -235,7 +235,7 @@ VRT_l_obj_status(struct sess *sp, int num)
} }
int int
VRT_r_obj_status(struct sess *sp) VRT_r_obj_status(const struct sess *sp)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
...@@ -243,7 +243,7 @@ VRT_r_obj_status(struct sess *sp) ...@@ -243,7 +243,7 @@ VRT_r_obj_status(struct sess *sp)
} }
void void
VRT_l_resp_status(struct sess *sp, int num) VRT_l_resp_status(const struct sess *sp, int num)
{ {
char *p; char *p;
...@@ -279,7 +279,7 @@ VRT_handling(struct sess *sp, unsigned hand) ...@@ -279,7 +279,7 @@ VRT_handling(struct sess *sp, unsigned hand)
*/ */
void void
VRT_l_obj_ttl(struct sess *sp, double a) VRT_l_obj_ttl(const struct sess *sp, double a)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
...@@ -294,7 +294,7 @@ VRT_l_obj_ttl(struct sess *sp, double a) ...@@ -294,7 +294,7 @@ VRT_l_obj_ttl(struct sess *sp, double a)
} }
double double
VRT_r_obj_ttl(struct sess *sp) VRT_r_obj_ttl(const struct sess *sp)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */
...@@ -305,7 +305,7 @@ VRT_r_obj_ttl(struct sess *sp) ...@@ -305,7 +305,7 @@ VRT_r_obj_ttl(struct sess *sp)
#define VOBJ(type,onm,field) \ #define VOBJ(type,onm,field) \
void \ void \
VRT_l_obj_##onm(struct sess *sp, type a) \ VRT_l_obj_##onm(const struct sess *sp, type a) \
{ \ { \
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); \ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); \
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ \ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ \
...@@ -313,7 +313,7 @@ VRT_l_obj_##onm(struct sess *sp, type a) \ ...@@ -313,7 +313,7 @@ VRT_l_obj_##onm(struct sess *sp, type a) \
} \ } \
\ \
type \ type \
VRT_r_obj_##onm(struct sess *sp) \ VRT_r_obj_##onm(const struct sess *sp) \
{ \ { \
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); \ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); \
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ \ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ \
...@@ -343,7 +343,7 @@ VRT_r_req_backend(struct sess *sp) ...@@ -343,7 +343,7 @@ VRT_r_req_backend(struct sess *sp)
#define VREQ(n1, n2) \ #define VREQ(n1, n2) \
const char * \ const char * \
VRT_r_req_##n1(struct sess *sp) \ VRT_r_req_##n1(const struct sess *sp) \
{ \ { \
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); \ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); \
CHECK_OBJ_NOTNULL(sp->http, HTTP_MAGIC); \ CHECK_OBJ_NOTNULL(sp->http, HTTP_MAGIC); \
...@@ -357,7 +357,7 @@ VREQ(proto, HTTP_HDR_PROTO) ...@@ -357,7 +357,7 @@ VREQ(proto, HTTP_HDR_PROTO)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
const char * const char *
VRT_r_resp_proto(struct sess *sp) VRT_r_resp_proto(const struct sess *sp)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
...@@ -365,7 +365,7 @@ VRT_r_resp_proto(struct sess *sp) ...@@ -365,7 +365,7 @@ VRT_r_resp_proto(struct sess *sp)
} }
const char * const char *
VRT_r_resp_response(struct sess *sp) VRT_r_resp_response(const struct sess *sp)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
...@@ -373,7 +373,7 @@ VRT_r_resp_response(struct sess *sp) ...@@ -373,7 +373,7 @@ VRT_r_resp_response(struct sess *sp)
} }
int int
VRT_r_resp_status(struct sess *sp) VRT_r_resp_status(const struct sess *sp)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
...@@ -383,7 +383,7 @@ VRT_r_resp_status(struct sess *sp) ...@@ -383,7 +383,7 @@ VRT_r_resp_status(struct sess *sp)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
struct sockaddr * struct sockaddr *
VRT_r_client_ip(struct sess *sp) VRT_r_client_ip(const struct sess *sp)
{ {
return (sp->sockaddr); return (sp->sockaddr);
...@@ -428,7 +428,7 @@ VRT_l_req_hash(struct sess *sp, const char *str) ...@@ -428,7 +428,7 @@ VRT_l_req_hash(struct sess *sp, const char *str)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
double double
VRT_r_now(struct sess *sp) VRT_r_now(const struct sess *sp)
{ {
(void)sp; (void)sp;
...@@ -436,7 +436,7 @@ VRT_r_now(struct sess *sp) ...@@ -436,7 +436,7 @@ VRT_r_now(struct sess *sp)
} }
double double
VRT_r_obj_lastuse(struct sess *sp) VRT_r_obj_lastuse(const struct sess *sp)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
...@@ -445,18 +445,18 @@ VRT_r_obj_lastuse(struct sess *sp) ...@@ -445,18 +445,18 @@ VRT_r_obj_lastuse(struct sess *sp)
} }
int int
VRT_r_backend_health(struct sess *sp) VRT_r_backend_health(const struct sess *sp)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC);
return sp->backend->health; return (sp->backend->health);
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
char * char *
VRT_IP_string(struct sess *sp, struct sockaddr *sa) VRT_IP_string(const struct sess *sp, const struct sockaddr *sa)
{ {
char h[64], p[8], *q; char h[64], p[8], *q;
socklen_t len = 0; socklen_t len = 0;
...@@ -483,7 +483,7 @@ VRT_IP_string(struct sess *sp, struct sockaddr *sa) ...@@ -483,7 +483,7 @@ VRT_IP_string(struct sess *sp, struct sockaddr *sa)
} }
char * char *
VRT_int_string(struct sess *sp, int num) VRT_int_string(const struct sess *sp, int num)
{ {
char *p; char *p;
int size = 12; int size = 12;
......
...@@ -60,7 +60,7 @@ static uint32_t ipv4mask[] = { ...@@ -60,7 +60,7 @@ static uint32_t ipv4mask[] = {
}; };
static int static int
vrt_acl_vsl(struct sess *sp, const char *acln, struct vrt_acl *ap, int r) vrt_acl_vsl(const struct sess *sp, const char *acln, const struct vrt_acl *ap, int r)
{ {
AN(ap); AN(ap);
...@@ -83,7 +83,7 @@ vrt_acl_vsl(struct sess *sp, const char *acln, struct vrt_acl *ap, int r) ...@@ -83,7 +83,7 @@ vrt_acl_vsl(struct sess *sp, const char *acln, struct vrt_acl *ap, int r)
} }
int int
VRT_acl_match(struct sess *sp, struct sockaddr *sa, const char *acln, struct vrt_acl *ap) VRT_acl_match(const struct sess *sp, struct sockaddr *sa, const char *acln, const struct vrt_acl *ap)
{ {
struct addrinfo *a1; struct addrinfo *a1;
struct sockaddr_in *sin1, *sin2; struct sockaddr_in *sin1, *sin2;
......
...@@ -102,7 +102,7 @@ VRT_re_test(struct vsb *sb, const char *re, int sub) ...@@ -102,7 +102,7 @@ VRT_re_test(struct vsb *sb, const char *re, int sub)
} }
const char * const char *
VRT_regsub(struct sess *sp, const char *str, void *re, const char *sub) VRT_regsub(const struct sess *sp, const char *str, void *re, const char *sub)
{ {
regmatch_t pm[10]; regmatch_t pm[10];
regex_t *t; regex_t *t;
......
...@@ -87,7 +87,7 @@ struct vrt_acl { ...@@ -87,7 +87,7 @@ struct vrt_acl {
}; };
/* ACL related */ /* ACL related */
int VRT_acl_match(struct sess *, struct sockaddr *, const char *, struct vrt_acl *); int VRT_acl_match(const struct sess *, struct sockaddr *, const char *, const struct vrt_acl *);
void VRT_acl_init(struct vrt_acl *); void VRT_acl_init(struct vrt_acl *);
void VRT_acl_fini(struct vrt_acl *); void VRT_acl_fini(struct vrt_acl *);
...@@ -96,18 +96,18 @@ void VRT_re_init(void **, const char *, int sub); ...@@ -96,18 +96,18 @@ void VRT_re_init(void **, const char *, int sub);
void VRT_re_fini(void *); void VRT_re_fini(void *);
int VRT_re_match(const char *, void *re); int VRT_re_match(const char *, void *re);
int VRT_re_test(struct vsb *, const char *, int sub); int VRT_re_test(struct vsb *, const char *, int sub);
const char *VRT_regsub(struct sess *sp, const char *, void *, const char *); const char *VRT_regsub(const struct sess *sp, const char *, void *, const char *);
void VRT_purge(const char *, int hash); void VRT_purge(const char *, int hash);
void VRT_count(struct sess *, unsigned); void VRT_count(const struct sess *, unsigned);
int VRT_rewrite(const char *, const char *); int VRT_rewrite(const char *, const char *);
void VRT_error(struct sess *, unsigned, const char *); void VRT_error(struct sess *, unsigned, const char *);
int VRT_switch_config(const char *); int VRT_switch_config(const char *);
enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ }; enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ };
char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *); char *VRT_GetHdr(const struct sess *, enum gethdr_e where, const char *);
void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, const char *, ...); void VRT_SetHdr(const struct sess *, enum gethdr_e where, const char *, const char *, ...);
void VRT_handling(struct sess *sp, unsigned hand); void VRT_handling(struct sess *sp, unsigned hand);
/* Simple stuff */ /* Simple stuff */
...@@ -120,8 +120,8 @@ void VRT_init_round_robin_backend(struct backend **, const struct vrt_round_robi ...@@ -120,8 +120,8 @@ void VRT_init_round_robin_backend(struct backend **, const struct vrt_round_robi
void VRT_init_random_backend(struct backend **, const struct vrt_random_backend *); void VRT_init_random_backend(struct backend **, const struct vrt_random_backend *);
void VRT_fini_backend(struct backend *); void VRT_fini_backend(struct backend *);
char *VRT_IP_string(struct sess *sp, struct sockaddr *sa); char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa);
char *VRT_int_string(struct sess *sp, int); char *VRT_int_string(const struct sess *sp, int);
#define VRT_done(sp, hand) \ #define VRT_done(sp, hand) \
do { \ do { \
......
...@@ -10,41 +10,41 @@ void VRT_l_backend_host(struct backend *, const char *); ...@@ -10,41 +10,41 @@ void VRT_l_backend_host(struct backend *, const char *);
void VRT_l_backend_port(struct backend *, const char *); void VRT_l_backend_port(struct backend *, const char *);
void VRT_l_backend_dnsttl(struct backend *, double); void VRT_l_backend_dnsttl(struct backend *, double);
void VRT_l_backend_set(struct backend *, struct vrt_backend_entry *); void VRT_l_backend_set(struct backend *, struct vrt_backend_entry *);
struct sockaddr * VRT_r_client_ip(struct sess *); struct sockaddr * VRT_r_client_ip(const struct sess *);
struct sockaddr * VRT_r_server_ip(struct sess *); struct sockaddr * VRT_r_server_ip(struct sess *);
const char * VRT_r_req_request(struct sess *); const char * VRT_r_req_request(const struct sess *);
void VRT_l_req_request(struct sess *, const char *, ...); void VRT_l_req_request(const struct sess *, const char *, ...);
const char * VRT_r_req_url(struct sess *); const char * VRT_r_req_url(const struct sess *);
void VRT_l_req_url(struct sess *, const char *, ...); void VRT_l_req_url(const struct sess *, const char *, ...);
const char * VRT_r_req_proto(struct sess *); const char * VRT_r_req_proto(const struct sess *);
void VRT_l_req_proto(struct sess *, const char *, ...); void VRT_l_req_proto(const struct sess *, const char *, ...);
void VRT_l_req_hash(struct sess *, const char *); void VRT_l_req_hash(struct sess *, const char *);
struct backend * VRT_r_req_backend(struct sess *); struct backend * VRT_r_req_backend(struct sess *);
void VRT_l_req_backend(struct sess *, struct backend *); void VRT_l_req_backend(struct sess *, struct backend *);
const char * VRT_r_bereq_request(struct sess *); const char * VRT_r_bereq_request(const struct sess *);
void VRT_l_bereq_request(struct sess *, const char *, ...); void VRT_l_bereq_request(const struct sess *, const char *, ...);
const char * VRT_r_bereq_url(struct sess *); const char * VRT_r_bereq_url(const struct sess *);
void VRT_l_bereq_url(struct sess *, const char *, ...); void VRT_l_bereq_url(const struct sess *, const char *, ...);
const char * VRT_r_bereq_proto(struct sess *); const char * VRT_r_bereq_proto(const struct sess *);
void VRT_l_bereq_proto(struct sess *, const char *, ...); void VRT_l_bereq_proto(const struct sess *, const char *, ...);
const char * VRT_r_obj_proto(struct sess *); const char * VRT_r_obj_proto(const struct sess *);
void VRT_l_obj_proto(struct sess *, const char *, ...); void VRT_l_obj_proto(const struct sess *, const char *, ...);
int VRT_r_obj_status(struct sess *); int VRT_r_obj_status(const struct sess *);
void VRT_l_obj_status(struct sess *, int); void VRT_l_obj_status(const struct sess *, int);
const char * VRT_r_obj_response(struct sess *); const char * VRT_r_obj_response(const struct sess *);
void VRT_l_obj_response(struct sess *, const char *, ...); void VRT_l_obj_response(const struct sess *, const char *, ...);
unsigned VRT_r_obj_valid(struct sess *); unsigned VRT_r_obj_valid(const struct sess *);
void VRT_l_obj_valid(struct sess *, unsigned); void VRT_l_obj_valid(const struct sess *, unsigned);
unsigned VRT_r_obj_cacheable(struct sess *); unsigned VRT_r_obj_cacheable(const struct sess *);
void VRT_l_obj_cacheable(struct sess *, unsigned); void VRT_l_obj_cacheable(const struct sess *, unsigned);
double VRT_r_obj_ttl(struct sess *); double VRT_r_obj_ttl(const struct sess *);
void VRT_l_obj_ttl(struct sess *, double); void VRT_l_obj_ttl(const struct sess *, double);
double VRT_r_obj_lastuse(struct sess *); double VRT_r_obj_lastuse(const struct sess *);
const char * VRT_r_resp_proto(struct sess *); const char * VRT_r_resp_proto(const struct sess *);
void VRT_l_resp_proto(struct sess *, const char *, ...); void VRT_l_resp_proto(const struct sess *, const char *, ...);
int VRT_r_resp_status(struct sess *); int VRT_r_resp_status(const struct sess *);
void VRT_l_resp_status(struct sess *, int); void VRT_l_resp_status(const struct sess *, int);
const char * VRT_r_resp_response(struct sess *); const char * VRT_r_resp_response(const struct sess *);
void VRT_l_resp_response(struct sess *, const char *, ...); void VRT_l_resp_response(const struct sess *, const char *, ...);
double VRT_r_now(struct sess *); double VRT_r_now(const struct sess *);
int VRT_r_backend_health(struct sess *); int VRT_r_backend_health(const struct sess *);
...@@ -42,7 +42,7 @@ static void ...@@ -42,7 +42,7 @@ static void
vcc_acl_top(struct tokenlist *tl, const char *acln) vcc_acl_top(struct tokenlist *tl, const char *acln)
{ {
Fh(tl, 1, "\nstatic struct vrt_acl acl_%s[] = {\n", acln); Fh(tl, 1, "\nstatic const struct vrt_acl acl_%s[] = {\n", acln);
tl->hindent += INDENT; tl->hindent += INDENT;
} }
......
...@@ -465,7 +465,7 @@ vcl_output_lang_h(struct vsb *sb) ...@@ -465,7 +465,7 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, "};\n"); vsb_cat(sb, "};\n");
vsb_cat(sb, "\n"); vsb_cat(sb, "\n");
vsb_cat(sb, "/* ACL related */\n"); vsb_cat(sb, "/* ACL related */\n");
vsb_cat(sb, "int VRT_acl_match(struct sess *, struct sockaddr *, const char *, struct vrt_acl *);\n"); vsb_cat(sb, "int VRT_acl_match(const struct sess *, struct sockaddr *, const char *, const struct vrt_acl *);\n");
vsb_cat(sb, "void VRT_acl_init(struct vrt_acl *);\n"); vsb_cat(sb, "void VRT_acl_init(struct vrt_acl *);\n");
vsb_cat(sb, "void VRT_acl_fini(struct vrt_acl *);\n"); vsb_cat(sb, "void VRT_acl_fini(struct vrt_acl *);\n");
vsb_cat(sb, "\n"); vsb_cat(sb, "\n");
...@@ -474,18 +474,18 @@ vcl_output_lang_h(struct vsb *sb) ...@@ -474,18 +474,18 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, "void VRT_re_fini(void *);\n"); vsb_cat(sb, "void VRT_re_fini(void *);\n");
vsb_cat(sb, "int VRT_re_match(const char *, void *re);\n"); vsb_cat(sb, "int VRT_re_match(const char *, void *re);\n");
vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *, int sub);\n"); vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *, int sub);\n");
vsb_cat(sb, "const char *VRT_regsub(struct sess *sp, const char *, void *, const char *);\n"); vsb_cat(sb, "const char *VRT_regsub(const struct sess *sp, const char *, void *, const char *);\n");
vsb_cat(sb, "\n"); vsb_cat(sb, "\n");
vsb_cat(sb, "void VRT_purge(const char *, int hash);\n"); vsb_cat(sb, "void VRT_purge(const char *, int hash);\n");
vsb_cat(sb, "\n"); vsb_cat(sb, "\n");
vsb_cat(sb, "void VRT_count(struct sess *, unsigned);\n"); vsb_cat(sb, "void VRT_count(const struct sess *, unsigned);\n");
vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n"); vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n");
vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);\n"); vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);\n");
vsb_cat(sb, "int VRT_switch_config(const char *);\n"); vsb_cat(sb, "int VRT_switch_config(const char *);\n");
vsb_cat(sb, "\n"); vsb_cat(sb, "\n");
vsb_cat(sb, "enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ };\n"); vsb_cat(sb, "enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ };\n");
vsb_cat(sb, "char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *);\n"); vsb_cat(sb, "char *VRT_GetHdr(const struct sess *, enum gethdr_e where, const char *);\n");
vsb_cat(sb, "void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, const char *, ...);\n"); vsb_cat(sb, "void VRT_SetHdr(const struct sess *, enum gethdr_e where, const char *, const char *, ...);\n");
vsb_cat(sb, "void VRT_handling(struct sess *sp, unsigned hand);\n"); vsb_cat(sb, "void VRT_handling(struct sess *sp, unsigned hand);\n");
vsb_cat(sb, "\n"); vsb_cat(sb, "\n");
vsb_cat(sb, "/* Simple stuff */\n"); vsb_cat(sb, "/* Simple stuff */\n");
...@@ -498,8 +498,8 @@ vcl_output_lang_h(struct vsb *sb) ...@@ -498,8 +498,8 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, "void VRT_init_random_backend(struct backend **, const struct vrt_random_backend *);\n"); vsb_cat(sb, "void VRT_init_random_backend(struct backend **, const struct vrt_random_backend *);\n");
vsb_cat(sb, "void VRT_fini_backend(struct backend *);\n"); vsb_cat(sb, "void VRT_fini_backend(struct backend *);\n");
vsb_cat(sb, "\n"); vsb_cat(sb, "\n");
vsb_cat(sb, "char *VRT_IP_string(struct sess *sp, struct sockaddr *sa);\n"); vsb_cat(sb, "char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa);\n");
vsb_cat(sb, "char *VRT_int_string(struct sess *sp, int);\n"); vsb_cat(sb, "char *VRT_int_string(const struct sess *sp, int);\n");
vsb_cat(sb, "\n"); vsb_cat(sb, "\n");
vsb_cat(sb, "#define VRT_done(sp, hand) \\\n"); vsb_cat(sb, "#define VRT_done(sp, hand) \\\n");
vsb_cat(sb, " do { \\\n"); vsb_cat(sb, " do { \\\n");
...@@ -518,42 +518,42 @@ vcl_output_lang_h(struct vsb *sb) ...@@ -518,42 +518,42 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, "void VRT_l_backend_port(struct backend *, const char *);\n"); vsb_cat(sb, "void VRT_l_backend_port(struct backend *, const char *);\n");
vsb_cat(sb, "void VRT_l_backend_dnsttl(struct backend *, double);\n"); vsb_cat(sb, "void VRT_l_backend_dnsttl(struct backend *, double);\n");
vsb_cat(sb, "void VRT_l_backend_set(struct backend *, struct vrt_backend_entry *);\n"); vsb_cat(sb, "void VRT_l_backend_set(struct backend *, struct vrt_backend_entry *);\n");
vsb_cat(sb, "struct sockaddr * VRT_r_client_ip(struct sess *);\n"); vsb_cat(sb, "struct sockaddr * VRT_r_client_ip(const struct sess *);\n");
vsb_cat(sb, "struct sockaddr * VRT_r_server_ip(struct sess *);\n"); vsb_cat(sb, "struct sockaddr * VRT_r_server_ip(struct sess *);\n");
vsb_cat(sb, "const char * VRT_r_req_request(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_req_request(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_req_request(struct sess *, const char *, ...);\n"); vsb_cat(sb, "void VRT_l_req_request(const struct sess *, const char *, ...);\n");
vsb_cat(sb, "const char * VRT_r_req_url(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_req_url(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_req_url(struct sess *, const char *, ...);\n"); vsb_cat(sb, "void VRT_l_req_url(const struct sess *, const char *, ...);\n");
vsb_cat(sb, "const char * VRT_r_req_proto(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_req_proto(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_req_proto(struct sess *, const char *, ...);\n"); vsb_cat(sb, "void VRT_l_req_proto(const struct sess *, const char *, ...);\n");
vsb_cat(sb, "void VRT_l_req_hash(struct sess *, const char *);\n"); vsb_cat(sb, "void VRT_l_req_hash(struct sess *, const char *);\n");
vsb_cat(sb, "struct backend * VRT_r_req_backend(struct sess *);\n"); vsb_cat(sb, "struct backend * VRT_r_req_backend(struct sess *);\n");
vsb_cat(sb, "void VRT_l_req_backend(struct sess *, struct backend *);\n"); vsb_cat(sb, "void VRT_l_req_backend(struct sess *, struct backend *);\n");
vsb_cat(sb, "const char * VRT_r_bereq_request(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_bereq_request(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_bereq_request(struct sess *, const char *, ...);\n"); vsb_cat(sb, "void VRT_l_bereq_request(const struct sess *, const char *, ...);\n");
vsb_cat(sb, "const char * VRT_r_bereq_url(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_bereq_url(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_bereq_url(struct sess *, const char *, ...);\n"); vsb_cat(sb, "void VRT_l_bereq_url(const struct sess *, const char *, ...);\n");
vsb_cat(sb, "const char * VRT_r_bereq_proto(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_bereq_proto(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_bereq_proto(struct sess *, const char *, ...);\n"); vsb_cat(sb, "void VRT_l_bereq_proto(const struct sess *, const char *, ...);\n");
vsb_cat(sb, "const char * VRT_r_obj_proto(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_obj_proto(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_obj_proto(struct sess *, const char *, ...);\n"); vsb_cat(sb, "void VRT_l_obj_proto(const struct sess *, const char *, ...);\n");
vsb_cat(sb, "int VRT_r_obj_status(struct sess *);\n"); vsb_cat(sb, "int VRT_r_obj_status(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_obj_status(struct sess *, int);\n"); vsb_cat(sb, "void VRT_l_obj_status(const struct sess *, int);\n");
vsb_cat(sb, "const char * VRT_r_obj_response(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_obj_response(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_obj_response(struct sess *, const char *, ...);\n"); vsb_cat(sb, "void VRT_l_obj_response(const struct sess *, const char *, ...);\n");
vsb_cat(sb, "unsigned VRT_r_obj_valid(struct sess *);\n"); vsb_cat(sb, "unsigned VRT_r_obj_valid(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_obj_valid(struct sess *, unsigned);\n"); vsb_cat(sb, "void VRT_l_obj_valid(const struct sess *, unsigned);\n");
vsb_cat(sb, "unsigned VRT_r_obj_cacheable(struct sess *);\n"); vsb_cat(sb, "unsigned VRT_r_obj_cacheable(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_obj_cacheable(struct sess *, unsigned);\n"); vsb_cat(sb, "void VRT_l_obj_cacheable(const struct sess *, unsigned);\n");
vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n"); vsb_cat(sb, "double VRT_r_obj_ttl(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n"); vsb_cat(sb, "void VRT_l_obj_ttl(const struct sess *, double);\n");
vsb_cat(sb, "double VRT_r_obj_lastuse(struct sess *);\n"); vsb_cat(sb, "double VRT_r_obj_lastuse(const struct sess *);\n");
vsb_cat(sb, "const char * VRT_r_resp_proto(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_resp_proto(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_resp_proto(struct sess *, const char *, ...);\n"); vsb_cat(sb, "void VRT_l_resp_proto(const struct sess *, const char *, ...);\n");
vsb_cat(sb, "int VRT_r_resp_status(struct sess *);\n"); vsb_cat(sb, "int VRT_r_resp_status(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_resp_status(struct sess *, int);\n"); vsb_cat(sb, "void VRT_l_resp_status(const struct sess *, int);\n");
vsb_cat(sb, "const char * VRT_r_resp_response(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_resp_response(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *, ...);\n"); vsb_cat(sb, "void VRT_l_resp_response(const struct sess *, const char *, ...);\n");
vsb_cat(sb, "double VRT_r_now(struct sess *);\n"); vsb_cat(sb, "double VRT_r_now(const struct sess *);\n");
vsb_cat(sb, "int VRT_r_backend_health(struct sess *);\n"); vsb_cat(sb, "int VRT_r_backend_health(const struct sess *);\n");
} }
...@@ -32,10 +32,10 @@ ...@@ -32,10 +32,10 @@
# Objects available in backends # Objects available in backends
set beobj { set beobj {
{ backend.host WO HOSTNAME {} } { backend.host WO HOSTNAME {} "struct backend *"}
{ backend.port WO PORTNAME {} } { backend.port WO PORTNAME {} "struct backend *"}
{ backend.dnsttl WO TIME {} } { backend.dnsttl WO TIME {} "struct backend *"}
{ backend.set WO SET {} } { backend.set WO SET {} "struct backend *"}
} }
# Variables available in sessions # Variables available in sessions
...@@ -46,116 +46,138 @@ set spobj { ...@@ -46,116 +46,138 @@ set spobj {
{ client.ip { client.ip
RO IP RO IP
{recv pipe pass hash miss hit fetch deliver } {recv pipe pass hash miss hit fetch deliver }
"const struct sess *"
} }
{ client.bandwidth # Not implemented yet { client.bandwidth # Not implemented yet
NO NO
{ }
"const struct sess *"
} }
{ server.ip { server.ip
RO IP RO IP
{recv pipe pass hash miss hit fetch deliver } {recv pipe pass hash miss hit fetch deliver }
"struct sess *"
} }
# Request paramters # Request paramters
{ req.request { req.request
RW STRING RW STRING
{recv pipe pass hash miss hit fetch } {recv pipe pass hash miss hit fetch }
"const struct sess *"
} }
{ req.url { req.url
RW STRING RW STRING
{recv pipe pass hash miss hit fetch } {recv pipe pass hash miss hit fetch }
"const struct sess *"
} }
{ req.proto { req.proto
RW STRING RW STRING
{recv pipe pass hash miss hit fetch } {recv pipe pass hash miss hit fetch }
"const struct sess *"
} }
{ req.http. { req.http.
RW HEADER RW HDR_REQ
{recv pipe pass hash miss hit fetch } {recv pipe pass hash miss hit fetch }
HDR_REQ "const struct sess *"
} }
# Possibly misnamed, not really part of the request # Possibly misnamed, not really part of the request
{ req.hash { req.hash
WO HASH WO HASH
{ hash } { hash }
"struct sess *"
} }
{ req.backend { req.backend
RW BACKEND RW BACKEND
{recv pipe pass hash miss hit fetch } {recv pipe pass hash miss hit fetch }
"struct sess *"
} }
# Request sent to backend # Request sent to backend
{ bereq.request { bereq.request
RW STRING RW STRING
{ pipe pass miss } { pipe pass miss }
"const struct sess *"
} }
{ bereq.url { bereq.url
RW STRING RW STRING
{ pipe pass miss } { pipe pass miss }
"const struct sess *"
} }
{ bereq.proto { bereq.proto
RW STRING RW STRING
{ pipe pass miss } { pipe pass miss }
"const struct sess *"
} }
{ bereq.http. { bereq.http.
RW HEADER RW HDR_BEREQ
{ pipe pass miss } { pipe pass miss }
HDR_BEREQ "const struct sess *"
} }
# The (possibly) cached object # The (possibly) cached object
{ obj.proto { obj.proto
RW STRING RW STRING
{ hit fetch } { hit fetch }
"const struct sess *"
} }
{ obj.status { obj.status
RW INT RW INT
{ fetch } { fetch }
"const struct sess *"
} }
{ obj.response { obj.response
RW STRING RW STRING
{ fetch } { fetch }
"const struct sess *"
} }
{ obj.http. { obj.http.
RW HEADER RW HDR_OBJ
{ hit fetch } { hit fetch }
HDR_OBJ "const struct sess *"
} }
{ obj.valid { obj.valid
RW BOOL RW BOOL
{ hit fetch discard timeout} { hit fetch discard timeout}
"const struct sess *"
} }
{ obj.cacheable { obj.cacheable
RW BOOL RW BOOL
{ hit fetch discard timeout} { hit fetch discard timeout}
"const struct sess *"
} }
{ obj.ttl { obj.ttl
RW TIME RW TIME
{ hit fetch discard timeout} { hit fetch discard timeout}
"const struct sess *"
} }
{ obj.lastuse { obj.lastuse
RO TIME RO TIME
{ hit fetch deliver discard timeout} { hit fetch deliver discard timeout}
"const struct sess *"
} }
# The response we send back # The response we send back
{ resp.proto { resp.proto
RW STRING RW STRING
{ deliver } { deliver }
"const struct sess *"
} }
{ resp.status { resp.status
RW INT RW INT
{ deliver } { deliver }
"const struct sess *"
} }
{ resp.response { resp.response
RW STRING RW STRING
{ deliver } { deliver }
"const struct sess *"
} }
{ resp.http. { resp.http.
RW HEADER RW HDR_RESP
{ deliver } { deliver }
HDR_RESP "const struct sess *"
} }
# Miscellaneous # Miscellaneous
...@@ -164,24 +186,29 @@ set spobj { ...@@ -164,24 +186,29 @@ set spobj {
{ now { now
RO TIME RO TIME
{recv pipe pass hash miss hit fetch deliver discard timeout} {recv pipe pass hash miss hit fetch deliver discard timeout}
"const struct sess *"
} }
{ backend.health RO INT { backend.health RO INT
{recv pipe pass hash miss hit fetch deliver discard timeout} {recv pipe pass hash miss hit fetch deliver discard timeout}
"const struct sess *"
} }
} }
set tt(IP) "struct sockaddr *" set tt(IP) "struct sockaddr *"
set tt(STRING) "const char *" set tt(STRING) "const char *"
set tt(BOOL) "unsigned" set tt(BOOL) "unsigned"
set tt(BACKEND) "struct backend *" set tt(BACKEND) "struct backend *"
set tt(TIME) "double" set tt(TIME) "double"
set tt(INT) "int" set tt(INT) "int"
set tt(HEADER) "const char *" set tt(HDR_RESP) "const char *"
set tt(HOSTNAME) "const char *" set tt(HDR_OBJ) "const char *"
set tt(PORTNAME) "const char *" set tt(HDR_REQ) "const char *"
set tt(HASH) "const char *" set tt(HDR_BEREQ) "const char *"
set tt(SET) "struct vrt_backend_entry *" set tt(HOSTNAME) "const char *"
set tt(PORTNAME) "const char *"
set tt(HASH) "const char *"
set tt(SET) "struct vrt_backend_entry *"
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# Boilerplate warning for all generated files. # Boilerplate warning for all generated files.
...@@ -216,7 +243,7 @@ proc method_map {m} { ...@@ -216,7 +243,7 @@ proc method_map {m} {
return [string range $l 3 end] return [string range $l 3 end]
} }
proc vars {v ty pa} { proc vars {v pa} {
global tt fo fp global tt fo fp
regsub -all "#\[^\n\]*\n" $v "" v regsub -all "#\[^\n\]*\n" $v "" v
...@@ -226,10 +253,15 @@ proc vars {v ty pa} { ...@@ -226,10 +253,15 @@ proc vars {v ty pa} {
set a [lindex $v 1] set a [lindex $v 1]
if {$a == "NO"} continue if {$a == "NO"} continue
set t [lindex $v 2] set t [lindex $v 2]
puts $fo "\t\{ \"$n\", $t, [string length $n]," set ty [lindex $v 4]
if {[regexp HDR_ $t]} {
puts $fo "\t\{ \"$n\", HEADER, [string length $n],"
} else {
puts $fo "\t\{ \"$n\", $t, [string length $n],"
}
if {$a == "RO" || $a == "RW"} { if {$a == "RO" || $a == "RW"} {
puts $fo "\t \"VRT_r_${m}($pa)\"," puts $fo "\t \"VRT_r_${m}($pa)\","
if {$t != "HEADER"} { if {![regexp HDR_ $t]} {
puts $fp "$tt($t) VRT_r_${m}($ty);" puts $fp "$tt($t) VRT_r_${m}($ty);"
} }
} else { } else {
...@@ -237,7 +269,7 @@ proc vars {v ty pa} { ...@@ -237,7 +269,7 @@ proc vars {v ty pa} {
} }
if {$a == "WO" || $a == "RW"} { if {$a == "WO" || $a == "RW"} {
puts $fo "\t \"VRT_l_${m}($pa, \"," puts $fo "\t \"VRT_l_${m}($pa, \","
if {$t == "HEADER"} { if {[regexp HDR_ $t]} {
} elseif {$t == "STRING"} { } elseif {$t == "STRING"} {
puts $fp "void VRT_l_${m}($ty, $tt($t), ...);" puts $fp "void VRT_l_${m}($ty, $tt($t), ...);"
} else { } else {
...@@ -247,10 +279,10 @@ proc vars {v ty pa} { ...@@ -247,10 +279,10 @@ proc vars {v ty pa} {
puts $fo "\t NULL," puts $fo "\t NULL,"
} }
puts $fo "\t V_$a," puts $fo "\t V_$a,"
if {$t != "HEADER"} { if {![regexp HDR_ $t]} {
puts $fo "\t 0," puts $fo "\t 0,"
} else { } else {
puts $fo "\t \"[lindex $v 4]\"," puts $fo "\t \"$t\","
} }
puts $fo "\t [method_map [lindex $v 3]]" puts $fo "\t [method_map [lindex $v 3]]"
puts $fo "\t\}," puts $fo "\t\},"
...@@ -264,13 +296,13 @@ puts $fo "#include \"vcc_compile.h\"" ...@@ -264,13 +296,13 @@ puts $fo "#include \"vcc_compile.h\""
puts $fo "" puts $fo ""
puts $fo "struct var vcc_be_vars\[\] = {" puts $fo "struct var vcc_be_vars\[\] = {"
vars $beobj "struct backend *" "backend" vars $beobj "backend"
puts $fo "};" puts $fo "};"
puts $fo "" puts $fo ""
puts $fo "struct var vcc_vars\[\] = {" puts $fo "struct var vcc_vars\[\] = {"
vars $spobj "struct sess *" "sp" vars $spobj "sp"
puts $fo "};" puts $fo "};"
close $fp close $fp
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment