コード例 #1
0
ファイル: y_string.c プロジェクト: a-lex-leon/y-lib
// --------------------------------------------------------------------------------------------------
// Get the content of the parameter named "paramName" and return it as a char *
//
// Todo: Make a derivative function getParameterNoZeroes() which uses lr_eval_string_ext()
// and replaces all \x00 characters in the result with something else, like y_array_get_no_zeroes() does.
// Then every user of this function should start using it.
// Alternative: Make a function that cleans parameters of embedded null bytes and tell users to use that
// before doing anything else with possible tainted values.
// I think I like that one better to be honest. For the Array_ subset it's not that bad given the better
// memory management but for this one .. muh.
//
// @author Floris Kraak
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//        example usage:
//                char *test;
//                lr_save_string("test123", "TestParam");        // save the string "test123" into parameter {TestParam}
//                test=y_get_parameter("TestParam");
//                lr_message("Test: %s", test);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
char* y_get_parameter(const char* paramName)
{
   char *tmp = y_get_parameter_eval_string(paramName);
   char *parameter = lr_eval_string(tmp);
   free(tmp);
   
   return parameter;
}
コード例 #2
0
ファイル: y_core.c プロジェクト: linpelvis/y-lib
/*!
\brief Get the content of a parameter and return it as a char * (lr_eval_string_ext() version)

Like y_get_parameter, but the result will use lr_eval_string_ext() to acquire it's memory,
rather than getting it from lr_eval_string.
This can be useful when you want your data to remain in memory instead of getting freed at the end of each iteration.
An example is the browser emulation code in y_emulate_browser.c, which sets up a linked list that has to stay allocated throughout the duration of the test.
(And therefore never needs to be freed. But I digress.)

\param [in] source_param The name of the parameter to fetch.
\returns A char* buffer containing the contents of the parameter, allocated with lr_eval_string_ext()
\warning Memory allocated in this manner must be freed using lr_eval_string_ext_free() or it will linger.

\b Example:
\code
char *test;
lr_save_string("test123", "TestParam");        // save the string "test123" into parameter {TestParam}
test=y_get_parameter_ext("TestParam");
lr_message("Test: %s", test);
lr_eval_string_ext_free(test);
\endcode
\author Floris Kraak
\sa y_get_parameter(), lr_eval_string_ext()
*/
char* y_get_parameter_ext(const char *source_param)
{
    char* buffer;
    unsigned long size;
    char* source = y_get_parameter_eval_string(source_param); // Puts the parameter name into parameter seperators { }.
    lr_eval_string_ext(source, strlen(source), &buffer, &size, 0, 0, -1); // Evaluates the result and copy the data into buffer.
    free(source);                                             // Free the intermediate parameter name.
    return buffer;
}
コード例 #3
0
ファイル: y_string.c プロジェクト: a-lex-leon/y-lib
// --------------------------------------------------------------------------------------------------
// Semi-efficiënt parameter copy using lr_eval_string_ext() with appropriate freeing of memory.
// @author Floris Kraak
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//        example usage:
//                lr_save_string("text", "param_a");
//                y_copy_param("param_a", "param_b");   // Results in an exact copy of the content of param_a being stored in param_b.
//                lr_log_message(lr_eval_string("param_b: {param_b}")); // Prints "param_b: text".
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void y_copy_param(char* source_param, char* dest_param)
{
    unsigned long size;
    char* buffer;
    char* source = y_get_parameter_eval_string(source_param); // Puts the parameter name into parameter seperators { }. Resulting ptr must be freed.
    lr_eval_string_ext(source, strlen(source), &buffer, &size, 0, 0, -1); // Evaluates the result and copies the data into buffer.
    free(source);                              // Free the intermediate parameter name.
    lr_save_var(buffer, size, 0, dest_param);  // Save the result.
    lr_eval_string_ext_free(&buffer);          // Free the buffer.
}
コード例 #4
0
ファイル: y_string.c プロジェクト: a-lex-leon/y-lib
// --------------------------------------------------------------------------------------------------
// Test if the given parameter is empty or not yet set (these are two different things..)
// 
// @author Floris Kraak
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//        example usage:
// 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int y_is_empty_parameter(const char *param_name)
{
    char *param_eval_string = y_get_parameter_eval_string(param_name);
    char *param = lr_eval_string(param_eval_string);
    
    int result = strlen(param) == 0 || strcmp(param, param_eval_string) == 0;
    free(param_eval_string);

    return result;
}
コード例 #5
0
ファイル: y_core.c プロジェクト: linpelvis/y-lib
/*!
\brief Get the content of a parameter and return it as a char *, or return NULL if it wasn't set.

This will return null in the most typical case: A parameter saved with web_reg_save_param(), but never filled.
The actual check employed here is a test that looks if the parameter content matches the parameter name surrounded by brackets.

If the parameter was never filled, lr_eval_string() will return that. However, in many more elaborate cases we really need to know
if it was never filled to begin with. This function mimics the behaviour we really want to see in LR, but don't have.
(At least, not in LR 11.05, the version I'm working with.)

It would be really nice if there was a loadrunner built-in that did this.

\param [in] param_name The name of the parameter to fetch.
\returns A char* buffer containing the contents of the parameter, allocated by lr_eval_string(), or NULL.
\warning This returns memory allocated by lr_eval_string(). It is likely to disappear (get freed) at the end of the iteration.
\warning If the content of the parameter matches the name of the parameter surrounded by brackets this function will return NULL even if it's not empty.

\b Example:
\code
char *test;
lr_save_string("test123", "TestParam");        // save the string "test123" into parameter {TestParam}
test=y_get_parameter("TestParam");
lr_message("Test: %s", test);
\endcode
\sa y_get_parameter(), y_is_empty_parameter()
\author Floris Kraak
*/
char* y_get_parameter_or_null(const char* param_name)
{
    char* param_eval_string = y_get_parameter_eval_string(param_name);
    char* param = lr_eval_string(param_eval_string);

    int exists = strcmp(param, param_eval_string) != 0; // Result doesn't match the param eval string (eg: '{param}')
    //lr_log_message("y_get_parameter_or_null for param_name %s, pre-eval string is %s, lr_eval_string result is %s, exists: %d", param_name, param_eval_string, param, exists);
    free(param_eval_string);
    //lr_abort();

	return exists ? param: NULL;
}