Skip to content

Commit

Permalink
modify: key keeping method for headers.(req.http.*)
Browse files Browse the repository at this point in the history
  • Loading branch information
xcir committed Nov 23, 2012
1 parent 174721c commit 7858d44
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 171 deletions.
6 changes: 4 additions & 2 deletions README.rst
Expand Up @@ -7,8 +7,8 @@ Varnish parse data module
-------------------------

:Author: Syohei Tanaka(@xcir)
:Date: 2012-11-18
:Version: 0.9-iterate-2
:Date: 2012-11-23
:Version: 0.10
:Manual section: 3

SYNOPSIS
Expand Down Expand Up @@ -461,6 +461,8 @@ HISTORY
===========


Version 0.10: Add: param, size, body, next_key, next_offset, current_key, iterate, reset_offset

Version 0.9: Bug fix: always segfault on x86. And sometimes segfault on x86_64. [issue #5 Thanks comotion]

Version 0.8: Support unknown content-type.(post_body only) [issue #3 Thanks c0ze]
Expand Down
63 changes: 7 additions & 56 deletions src/vmod_parsereq.c
Expand Up @@ -5,13 +5,7 @@
///////////////////////////////////////////////////////////////
//キーのオフセット初期化
void vmod_reset_offset(struct sess *sp, const char* type){
unsigned ret = 0;
enum gethdr_e where = vmod_convhdrtype(type, &ret);
if(ret){
header_idx_reset(sp, where);
}else{
vmodreq_seek_reset(sp,vmod_convtype(type));
}
vmodreq_seek_reset(sp,vmod_convtype(type));
}

void vmod_post_seek_reset(struct sess *sp){
Expand All @@ -27,13 +21,7 @@ void vmod_cookie_seek_reset(struct sess *sp){
///////////////////////////////////////////////////////////////
//キーのオフセットを移動+移動後の値取得
const char *vmod_next_key(struct sess *sp, const char *type){
unsigned ret = 0;
enum gethdr_e where = vmod_convhdrtype(type, &ret);
if(ret){
return header_next(sp, where);
}else{
return vmodreq_seek(sp,vmod_convtype(type));
}
return vmodreq_seek(sp,vmod_convtype(type));
}

const char* vmod_get_read_keylist(struct sess *sp){
Expand All @@ -51,58 +39,21 @@ const char* vmod_cookie_read_keylist(struct sess *sp){
///////////////////////////////////////////////////////////////
//キーのオフセットを移動
void vmod_next_offset(struct sess *sp, const char *type){
unsigned ret = 0;
enum gethdr_e where = vmod_convhdrtype(type, &ret);
if(ret){
header_next(sp, where);
}else{
vmodreq_seek(sp,vmod_convtype(type));
}

vmodreq_seek(sp,vmod_convtype(type));

}

///////////////////////////////////////////////////////////////
//現在のキー名を取得
const char* vmod_current_key(struct sess *sp, const char* type){
unsigned ret = 0;
enum gethdr_e where = vmod_convhdrtype(type, &ret);
if(ret){
if(!vmodreq_get_raw(sp)){
VRT_panic(sp,"please write \"parsereq.init();\" to 1st line in vcl_recv.",vrt_magic_string_end);
}
struct vmod_request *c = vmodreq_get(sp);
switch (where) {
case HDR_REQ:
return get_header_key(sp, where, c->seek_idx_req);
break;
case HDR_BEREQ:
return get_header_key(sp, where, c->seek_idx_bereq);
break;
case HDR_BERESP:
return get_header_key(sp, where, c->seek_idx_beresp);
break;
case HDR_RESP:
return get_header_key(sp, where, c->seek_idx_resp);
break;
case HDR_OBJ:
return get_header_key(sp, where, c->seek_idx_obj);
break;
}
}else{
return vmod_read_cur(sp,vmod_convtype(type));
}
return vmod_read_cur(sp,vmod_convtype(type));

}

///////////////////////////////////////////////////////////////
//反復処理系
void vmod_iterate(struct sess *sp, const char* type, const char* p){
unsigned ret = 0;
enum gethdr_e where = vmod_convhdrtype(type, &ret);
if(ret){
header_iterate(sp, p, where);
}else{
vmod_read_iterate(sp,p,vmod_convtype(type));
}
vmod_read_iterate(sp,p,vmod_convtype(type));
}


Expand Down
21 changes: 12 additions & 9 deletions src/vmod_parsereq.h
Expand Up @@ -42,7 +42,7 @@ static unsigned is_debug = 0;

//////////////////////////////////////////
//for internal head
enum VMODREQ_TYPE { POST, GET, COOKIE };
enum VMODREQ_TYPE { POST, GET, COOKIE, REQ};

struct hdr {
char *key;
Expand All @@ -56,25 +56,24 @@ struct hdr {
struct vmod_headers {
unsigned magic;
#define VMOD_HEADERS_MAGIC 0x8d4d29ac
unsigned value_enabled;
char *seek;
// int count;//まだ値入れてないのであとで入れる
// int count;//まだ値入れてないのであとで入れる
VTAILQ_HEAD(, hdr) headers;
};



struct vmod_request {
unsigned magic;
#define VMOD_REQUEST_MAGIC 0x8d4f21af
struct vmod_headers* post;
struct vmod_headers* get;
struct vmod_headers* cookie;

int seek_idx_req;
int seek_idx_bereq;
int seek_idx_beresp;
int seek_idx_resp;
int seek_idx_obj;
struct vmod_headers* hdr_req;

unsigned init_req;
char seek_tmp[256];

int parse_ret;
Expand Down Expand Up @@ -102,6 +101,9 @@ ssize_t vmod_HTC_Read(struct worker *, struct http_conn *, void *, size_t );
static int vmod_Hook_unset_deliver(struct sess *);
static int vmod_Hook_unset_bereq(struct sess *);

static void vmodreq_headers_free(struct vmod_headers *);


const char *vmodreq_header(struct sess *, enum VMODREQ_TYPE , const char *);
void vmodreq_sethead(struct vmod_request *, enum VMODREQ_TYPE ,const char *, const char *,int);
struct vmod_headers *vmodreq_getheaders(struct vmod_request *, enum VMODREQ_TYPE );
Expand All @@ -118,6 +120,7 @@ int vmodreq_get_parse(struct sess *);
int vmodreq_cookie_parse(struct sess *);
int vmodreq_reqbody(struct sess *, char**,int*);
int vmodreq_post_parse(struct sess *);
void init_header(const struct sess *, enum gethdr_e);

const char *vmodreq_getheader(struct vmod_request *, enum VMODREQ_TYPE , const char *);
int vmodreq_getheadersize(struct vmod_request *, enum VMODREQ_TYPE , const char *);
Expand All @@ -143,6 +146,6 @@ void gen_hdrtxt(const char *, char *, int);
int count_header(const struct sess *, enum gethdr_e );
struct http * vrt_selecthttp(const struct sess *, enum gethdr_e);
const char*get_header_key(const struct sess *, enum gethdr_e , int );
const char *header_next(const struct sess *, enum gethdr_e );
void header_idx_reset(const struct sess *, enum gethdr_e );
//const char *header_next(const struct sess *, enum gethdr_e );
//void header_idx_reset(const struct sess *, enum gethdr_e );
void header_iterate(struct sess *, const char* , enum gethdr_e );

0 comments on commit 7858d44

Please sign in to comment.