src/payload.c
static int
smp_fetch_payload_lv(struct proxy *px, struct session *s, void *l7, unsigned int opt,
                     const struct arg *arg_p, struct sample *smp)
{
	unsigned int len_offset = arg_p[0].data.uint;
	unsigned int len_size = arg_p[1].data.uint;
	unsigned int buf_offset;
	unsigned int buf_size = 0;
	struct channel *chn;
	int i;

	/* Format is (len offset, len size, buf offset) or (len offset, len size) */
	/* by default buf offset == len offset + len size */
	/* buf offset could be absolute or relative to len offset + len size if prefixed by + or - */

	if (!s)
		return 0;

	chn = ((opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? s->rep : s->req;

	if (!chn)
		return 0;

	if (len_offset + len_size > chn->buf->i)
		goto too_short;

	for (i = 0; i < len_size; i++) {
		buf_size = (buf_size << 8) + ((unsigned char *)chn->buf->p)[i + len_offset];
	}

	/* buf offset may be implicit, absolute or relative */
	buf_offset = len_offset + len_size;
	if (arg_p[2].type == ARGT_UINT)
		buf_offset = arg_p[2].data.uint;
	else if (arg_p[2].type == ARGT_SINT)
		buf_offset += arg_p[2].data.sint;

	if (!buf_size || buf_size > chn->buf->size || buf_offset + buf_size > chn->buf->size) {
		/* will never match */
		smp->flags = 0;
		return 0;
	}

	if (buf_offset + buf_size > chn->buf->i)
		goto too_short;

	/* init chunk as read only */
	smp->type = SMP_T_CBIN;
	chunk_initlen(&smp->data.str, chn->buf->p + buf_offset, 0, buf_size);
	smp->flags = SMP_F_VOLATILE;
	return 1;

 too_short:
	smp->flags = SMP_F_MAY_CHANGE;
	return 0;
}
/* extracts part of a payload with offset and length at a given position */
extracts part of a payload with offset and length at a given position
extracts part of a payload with offset and length at a given position
static int
smp_fetch_payload_lv(struct proxy *px, struct session *s, void *l7, unsigned int opt,
                     const struct arg *arg_p, struct sample *smp)
{
	unsigned int len_offset = arg_p[0].data.uint;
	unsigned int len_size = arg_p[1].data.uint;
	unsigned int buf_offset;
	unsigned int buf_size = 0;
	struct channel *chn;
	int i;
	if (!s)
		return 0;
	chn = ((opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? s->rep : s->req;
	if (!chn)
		return 0;
	if (len_offset + len_size > chn->buf->i)
		goto too_short;
	for (i = 0; i < len_size; i++) {
		buf_size = (buf_size << 8) + ((unsigned char *)chn->buf->p)[i + len_offset];
	}
	buf_offset = len_offset + len_size;
	if (arg_p[2].type == ARGT_UINT)
		buf_offset = arg_p[2].data.uint;
	else if (arg_p[2].type == ARGT_SINT)
		buf_offset += arg_p[2].data.sint;
	if (!buf_size || buf_size > chn->buf->size || buf_offset + buf_size > chn->buf->size) {
		smp->flags = 0;
		return 0;
	}
	if (buf_offset + buf_size > chn->buf->i)
		goto too_short;
	smp->type = SMP_T_CBIN;
	chunk_initlen(&smp->data.str, chn->buf->p + buf_offset, 0, buf_size);
	smp->flags = SMP_F_VOLATILE;
	return 1;
 too_short:
	smp->flags = SMP_F_MAY_CHANGE;
	return 0;
}
static int smp_fetch_payload_lv ( struct proxy * px , struct session * s , void * l7 , unsigned int opt , const struct arg * arg_p , struct sample * smp ) { unsigned int len_offset = arg_p [ 0 ] . data . uint ; unsigned int len_size = arg_p [ 1 ] . data . uint ; unsigned int buf_offset ; unsigned int buf_size = 0 ; struct channel * chn ; int i ; if ( ! s ) return 0 ; chn = ( ( opt & SMP_OPT_DIR ) == SMP_OPT_DIR_RES ) ? s -> rep : s -> req ; if ( ! chn ) return 0 ; if ( len_offset + len_size > chn -> buf -> i ) goto too_short ; for ( i = 0 ; i < len_size ; i ++ ) { buf_size = ( buf_size << 8 ) + ( ( unsigned char * ) chn -> buf -> p ) [ i + len_offset ] ; } buf_offset = len_offset + len_size ; if ( arg_p [ 2 ] . type == ARGT_UINT ) buf_offset = arg_p [ 2 ] . data . uint ; else if ( arg_p [ 2 ] . type == ARGT_SINT ) buf_offset += arg_p [ 2 ] . data . sint ; if ( ! buf_size || buf_size > chn -> buf -> size || buf_offset + buf_size > chn -> buf -> size ) { smp -> flags = 0 ; return 0 ; } if ( buf_offset + buf_size > chn -> buf -> i ) goto too_short ; smp -> type = SMP_T_CBIN ; chunk_initlen ( & smp -> data . str , chn -> buf -> p + buf_offset , 0 , buf_size ) ; smp -> flags = SMP_F_VOLATILE ; return 1 ; too_short : smp -> flags = SMP_F_MAY_CHANGE ; return 0 ; }
extracts part of a payload with offset and length at a given position
extracts part of a payload with offset and length at a given position
/* Format is (len offset, len size, buf offset) or (len offset, len size) */ /* by default buf offset == len offset + len size */ /* buf offset could be absolute or relative to len offset + len size if prefixed by + or - */ /* buf offset may be implicit, absolute or relative */ /* will never match */ /* init chunk as read only */