src/payload.c
int
smp_fetch_rdp_cookie(struct proxy *px, struct session *s, void *l7, unsigned int opt,
                     const struct arg *args, struct sample *smp)
{
	int bleft;
	const unsigned char *data;

	if (!s || !s->req)
		return 0;

	smp->flags = 0;
	smp->type = SMP_T_CSTR;

	bleft = s->req->buf->i;
	if (bleft <= 11)
		goto too_short;

	data = (const unsigned char *)s->req->buf->p + 11;
	bleft -= 11;

	if (bleft <= 7)
		goto too_short;

	if (strncasecmp((const char *)data, "Cookie:", 7) != 0)
		goto not_cookie;

	data += 7;
	bleft -= 7;

	while (bleft > 0 && *data == ' ') {
		data++;
		bleft--;
	}

	if (args) {

		if (bleft <= args->data.str.len)
			goto too_short;

		if ((data[args->data.str.len] != '=') ||
		    strncasecmp(args->data.str.str, (const char *)data, args->data.str.len) != 0)
			goto not_cookie;

		data += args->data.str.len + 1;
		bleft -= args->data.str.len + 1;
	} else {
		while (bleft > 0 && *data != '=') {
			if (*data == '\r' || *data == '\n')
				goto not_cookie;
			data++;
			bleft--;
		}

		if (bleft < 1)
			goto too_short;

		if (*data != '=')
			goto not_cookie;

		data++;
		bleft--;
	}

	/* data points to cookie value */
	smp->data.str.str = (char *)data;
	smp->data.str.len = 0;

	while (bleft > 0 && *data != '\r') {
		data++;
		bleft--;
	}

	if (bleft < 2)
		goto too_short;

	if (data[0] != '\r' || data[1] != '\n')
		goto not_cookie;

	smp->data.str.len = (char *)data - smp->data.str.str;
	smp->flags = SMP_F_VOLATILE;
	return 1;

 too_short:
	smp->flags = SMP_F_MAY_CHANGE;
 not_cookie:
	return 0;
}
/* Fetch the request RDP cookie identified in the args, or any cookie if no arg
 * is passed. It is usable both for ACL and for samples. Note: this decoder
 * only works with non-wrapping data. Accepts either 0 or 1 argument. Argument
 * is a string (cookie name), other types will lead to undefined behaviour.
 */
Fetch the request RDP cookie identified in the args, or any cookie if no arg
is passed. It is usable both for ACL and for samples. Note: this decoder
only works with non-wrapping data. Accepts either 0 or 1 argument. Argument
is a string (cookie name), other types will lead to undefined behaviour.
Fetch the request RDP cookie identified in the args or any cookie if no arg is passed . It is usable both for ACL and for samples . Note : this decoder only works with non - wrapping data . Accepts either 0 or 1 argument . Argument is a string ( cookie name ) other types will lead to undefined behaviour .
int
smp_fetch_rdp_cookie(struct proxy *px, struct session *s, void *l7, unsigned int opt,
                     const struct arg *args, struct sample *smp)
{
	int bleft;
	const unsigned char *data;
	if (!s || !s->req)
		return 0;
	smp->flags = 0;
	smp->type = SMP_T_CSTR;
	bleft = s->req->buf->i;
	if (bleft <= 11)
		goto too_short;
	data = (const unsigned char *)s->req->buf->p + 11;
	bleft -= 11;
	if (bleft <= 7)
		goto too_short;
	if (strncasecmp((const char *)data, "Cookie:", 7) != 0)
		goto not_cookie;
	data += 7;
	bleft -= 7;
	while (bleft > 0 && *data == ' ') {
		data++;
		bleft--;
	}
	if (args) {
		if (bleft <= args->data.str.len)
			goto too_short;
		if ((data[args->data.str.len] != '=') ||
		    strncasecmp(args->data.str.str, (const char *)data, args->data.str.len) != 0)
			goto not_cookie;
		data += args->data.str.len + 1;
		bleft -= args->data.str.len + 1;
	} else {
		while (bleft > 0 && *data != '=') {
			if (*data == '\r' || *data == '\n')
				goto not_cookie;
			data++;
			bleft--;
		}
		if (bleft < 1)
			goto too_short;
		if (*data != '=')
			goto not_cookie;
		data++;
		bleft--;
	}
	smp->data.str.str = (char *)data;
	smp->data.str.len = 0;
	while (bleft > 0 && *data != '\r') {
		data++;
		bleft--;
	}
	if (bleft < 2)
		goto too_short;
	if (data[0] != '\r' || data[1] != '\n')
		goto not_cookie;
	smp->data.str.len = (char *)data - smp->data.str.str;
	smp->flags = SMP_F_VOLATILE;
	return 1;
 too_short:
	smp->flags = SMP_F_MAY_CHANGE;
 not_cookie:
	return 0;
}
int smp_fetch_rdp_cookie ( struct proxy * px , struct session * s , void * l7 , unsigned int opt , const struct arg * args , struct sample * smp ) { int bleft ; const unsigned char * data ; if ( ! s || ! s -> req ) return 0 ; smp -> flags = 0 ; smp -> type = SMP_T_CSTR ; bleft = s -> req -> buf -> i ; if ( bleft <= 11 ) goto too_short ; data = ( const unsigned char * ) s -> req -> buf -> p + 11 ; bleft -= 11 ; if ( bleft <= 7 ) goto too_short ; if ( strncasecmp ( ( const char * ) data , " " , 7 ) != 0 ) goto not_cookie ; data += 7 ; bleft -= 7 ; while ( bleft > 0 && * data == ' ' ) { data ++ ; bleft -- ; } if ( args ) { if ( bleft <= args -> data . str . len ) goto too_short ; if ( ( data [ args -> data . str . len ] != ' ' ) || strncasecmp ( args -> data . str . str , ( const char * ) data , args -> data . str . len ) != 0 ) goto not_cookie ; data += args -> data . str . len + 1 ; bleft -= args -> data . str . len + 1 ; } else { while ( bleft > 0 && * data != ' ' ) { if ( * data == ' \r ' || * data == ' \n ' ) goto not_cookie ; data ++ ; bleft -- ; } if ( bleft < 1 ) goto too_short ; if ( * data != ' ' ) goto not_cookie ; data ++ ; bleft -- ; } smp -> data . str . str = ( char * ) data ; smp -> data . str . len = 0 ; while ( bleft > 0 && * data != ' \r ' ) { data ++ ; bleft -- ; } if ( bleft < 2 ) goto too_short ; if ( data [ 0 ] != ' \r ' || data [ 1 ] != ' \n ' ) goto not_cookie ; smp -> data . str . len = ( char * ) data - smp -> data . str . str ; smp -> flags = SMP_F_VOLATILE ; return 1 ; too_short : smp -> flags = SMP_F_MAY_CHANGE ; not_cookie : return 0 ; }
Fetch the request RDP cookie identified in the args, or any cookie if no arg
 is passed.
Fetch the request RDP cookie identified in the args or any cookie if no arg is passed .
/* data points to cookie value */