void
ngx_testmodule_post_read_request_body(ngx_http_request_t *r)
{
ngx_int_t totalreadsize;
ngx_int_t movepos;
ngx_chain_t * cl=NULL;
ngx_chain_t * cl2=NULL;
ngx_buf_t * buf=NULL;
char * container=NULL;
ngx_http_testmodule_conf_t * pConfig = NULL;
int split_returnvalue;
pConfig = ngx_http_get_module_loc_conf(r, ngx_http_testmodule_module);
if(r->request_body == NULL || r->request_body->bufs == NULL || r->request_body->bufs->buf == NULL)
{
ngx_http_finalize_request(r, NGX_DONE);
return;
}
cl = r->request_body->bufs;
if(cl->next == NULL)
{
buf = cl->buf;
totalreadsize = buf->last-buf->pos;
if(totalreadsize > 0)
{
container = (char *)ngx_pcalloc(r->pool, totalreadsize+1);
if(container == NULL)
{
ngx_http_finalize_request(r, NGX_DONE);
return;
}
memcpy(container, (char *)buf->pos, buf->last-buf->pos);
*(container+(buf->last-buf->pos)) = '\0';
}
else
{
ngx_http_finalize_request(r, NGX_DONE);
return;
}
}
else
{
totalreadsize = 0;
cl2 = cl;
while(cl2)
{
totalreadsize += cl2->buf->last - cl2->buf->pos;
cl2 = cl2->next;
}
if(totalreadsize > 0)
{
container = (char *)ngx_pcalloc(r->pool, totalreadsize+1);
if(container == NULL)
{
ngx_http_finalize_request(r, NGX_DONE);
return;
}
movepos = 0;
while(cl)
{
memcpy(container + movepos, (char *)cl->buf->pos, cl->buf->last - cl->buf->pos);
movepos += (cl->buf->last - cl->buf->pos);
cl = cl->next;
}
*(container + movepos) = '\0';
}
else
{
ngx_http_finalize_request(r, NGX_DONE);
return;
}
if(totalreadsize != movepos)
{
ngx_http_finalize_request(r, NGX_DONE);
return;
}
}
split_returnvalue = ngx_testmodule_log_write(r, container, totalreadsize);
ngx_http_finalize_request(r, NGX_DONE);
return;
}
ngx_http_testmodule_handler(ngx_http_request_t *r)
{
if (!(r->method & NGX_HTTP_POST)) {
return NGX_HTTP_NOT_ALLOWED;
}
else if(!pConfig->enable) {
return NGX_DECLINED;
}
rc_post = ngx_http_read_client_request_body(r, ngx_testmodule_post_read_request_body);
ngx_testmodule_resheader(r);
...
return ngx_http_send_response(r, NGX_HTTP_OK, &ngx_http_text_type, &cv);
}
i have tested my nginx module. but... i don't know.. difficult problem..
i am turning to you for help.