Share this page

# Example: lr_eval_string_ext

In Example 1, lr_eval_string_ext gets the contents and length of a parameter containing the null character.

In Example 2, lr_eval_string_ext retrieves the current URL to replace the recorded one.

Example 1

unsigned long prmLen;

char *newParam, *strStart;

// Create a parameter 39 characters long containing null characters.

lr_save_var("\0A A string\0 containing embedded Nulls\0",

39, 0, "Param1");

/*Since there are embedded NULL characters,

you cannot use strlen to get the string's length.

Use the prmLen argument instead.

Note that the second argument is the number of

characters in the parameter name "Param1", plus 2

for the parenthesis. */

lr_eval_string_ext ("{Param1}", 8, &newParam,

&prmLen, 0, 0,-1);

/* Output the length.*/

lr_output_message("The length is %d", prmLen);

// Action.c(24): The length is 39

// Point to the character after the first Null

strStart = newParam + 2;

// Output between the first and second Null

lr_output_message("The text is \"%s\"",strStart );

// Action.c(31): The text is " A string"

Example 2

In the following example, the lr_eval_string_ext function creates a buffer containing parameter data. The original URL generated during script recording will fail if it is replayed as is. We use lr_eval_string_ext to retrieve the current URL to replace the recorded one.

/* Original URL/

web_url("Response_1.dat",

"URL=http://209.88.184.66/SmWeb/Data/S_DFFA13B8DFB711D3AA6D009027
E00675/Response_1.dat",

"RecContentType=application/octet-stream",

"SupportFrames=0",

LAST );

web_save_header(RESPONSE, "headerVar")

web_create_html_param("returnedBuffer", "", "" ) ;

web_submit_data("SmartWeb.asp",

"Action=http:/207.86.104.1/SmWeb/Asp/SmartWeb.asp?App=Web&SmStream@,
"Method=POST",
"TargetFrame=",
"RecContentType=application/octet-stream",
"SupportFrames=0",
ITEMDATA,
"name=?App",
"value=Web",
ENDITEM,
"name=SmStream@Request",
"value=ClassDescription",
ENDITEM,
LAST );

/* Compute the length of the header */

len = strlen(lr_eval_string("{headerVar}") ) ;

/* Get a pointer to the buffer */

lr_eval_string_ext ("{Param1}", 8, &newParam, &prmLen, 0, 0,-1);

// Save the address

newParamAdr = newParam;

/* Retrieve the data from the buffer */

newParam += (len + 9) ; /* move the length of the header + 9 bytes */

fileLocationLength[0] = newParam[0] ; /* read the length of the buffer

fileLocationLength[1] = newParam[1] ; /* the first two bytes are relevant to us.. */

fileLocationLength[2] = 0 ;

fileLocationLength[3] = 0 ;

fileLocationLengthASCII = (short*)(&fileLocationLength[0]) ; /* cast this to a short* to be sure we only read two bytes */

newParam += 2 ; /* Move the pointer in the stream to the beginning of the actual string */

for(i=0, j=0 ; i <= *fileLocationLengthASCII; ++i)

if ( !memcmp( newParam, "\r\n", 1 ) ) {

/* Copy the new string into a char* called info */

memcpy(info[j], newParam[i], 1) ;

/* copy only ASCII characters and no Nulls */

++j ;

}

/* We now have a string, URL, which is the value we need for the next call. */

char* URL = strcat("URL=http://207.86.104.1", info) ;

web_url("Response_1.dat",

URL, /* this string now holds the correlated value */

"RecContentType=application/octet-stream",

"SupportFrames=0",

LAST );

lr_eval_string_ext_free(newParamAdr); /* free the pointer */

Tips to improve your search results... VuGen Function Reference Version 25.1-25.3 Function Reference 25.1-25.3 All View Local Help Center View Online Help Center Version: