Exemple #1
0
void OnMessageCB0 (const char* connectionID,
				  int isbinary,
				  const char * data,
				  int length)
{

int isupdate;

	
//		if (isbinary) {
//			lr_output_message("WebSocket ID = %s. [%d] bytes binary message received.", connectionID, length);
//		}
//		else {
//			lr_output_message("WebSocket ID = %s. [%d] bytes text message received.", connectionID, length);
//			lr_output_message("\r\n===\r\n%s\r\n===", data);
//		}

	OnMessageCB0_entries = OnMessageCB0_entries + 1;

// The first response after connect downloads JavaScript:  function setPhase,  c,d,z,n,r,p, error(cod, ph, tbl, msg), start, end, loop, retry, bw, convert.

   isupdate = strncmp(data,"d(",2); // as in data=d(1,8,1,'5.57','00:45:50','4.89','19500','5.57','5.58','25000',4);
if(isupdate != 0) {
   		// Display what is NOT handled as a message:
		lr_output_message(">> Among %d entries, OnMessageCB0_updates=%d with data=%s [at OnMessageCB0]"
		                  , OnMessageCB0_entries, OnMessageCB0_updates, data);
   }else{
	// message= z(1,10,'ELE Manufacturing','7.37','00:45:47','-3.15','49500','7.37','7.38','18000','5.97','9.11','7.61','7.7');
	//		    z(1,2,'Ations Europe','14.91','00:45:47','-7.33','47500','14.91','14.93','35000','12.62','19.43','16.09','16.2');
	
	    OnMessageCB0_updates = OnMessageCB0_updates + 1;
	if( OnMessageCB0_updates == 1 ){
		lr_set_transaction("T04_first_CB0_update", dTime_elapsed, LR_PASS); // Create successful transaction with a duration of seconds.
		lr_output_message(">> Among %d entries, OnMessageCB0_updates=%d with data=%s [at OnMessageCB0]"
		                  , OnMessageCB0_entries, OnMessageCB0_updates, data);
	}

	lr_save_param_regexp (
        			data,
        			length,
					myvalue_regexp,	
					"Ordinal=All",					
        			"ResultParam=myValue",
        			LAST );	
			
	if (atoi(lr_eval_string("{myValue_count}"))>0) {
		lr_message(">> [%s]: '%s'= [%s]$"
	    	           ,lr_eval_string("{ts}")
	    	           ,lr_eval_string("{COMPANY}")
	    	           ,lr_eval_string("{myValue_1}")
	    	          );
		lr_user_data_point(lr_eval_string("{COMPANY} stock value")
	    	           ,atof(lr_eval_string("{myValue_1}"))
	    	           );
	}
}
	
}
Exemple #2
0
void OnOpenCB0 (const char* connectionID,
				  const char * AccumulatedHeadersStr,
				  int AccumulatedHeadersLen)
{
	// Instead of lr_end_transaction("T03_Connect",LR_AUTO);
	dTime_elapsed = lr_end_timer(timer);
	lr_message("!!! connected at: [%s]",lr_eval_string("{ts}"));
	lr_set_transaction("T03_Connect", dTime_elapsed, LR_PASS); // Create successful transaction with a duration of seconds.

	lr_save_timestamp("timestamp", "DIGITS=16", LAST );
	lr_message(">> T03_Connect of WebSocket ID=%s after %.0f seconds at timestamp=%s [in OnOpenCB0()]"
	           ,connectionID ,dTime_elapsed ,lr_eval_string("{timestamp}"));

		lr_save_param_regexp (AccumulatedHeadersStr,
							  AccumulatedHeadersLen,
							  "RegExp=Sec-WebSocket-Accept: (.+)\\r\\n",
							  "ResultParam=Accept",
							  LAST );
		lr_output_message(">> Sec-WebSocket-Accept = [%s]",
						  lr_eval_string("{Accept}"));

	timer = lr_start_timer(); // instead of lr_start_transaction("T05_CB0_Updates") 
	OnMessageCB0_entries = 0;
}
Exemple #3
0
// --------------------------------------------------------------------------------------------------
// y_breadcrumb();
//         Adds a string to the parameter {breadcrumb}.
//      Use this to keep track of the steps taken by the script. Very useful is you have a script which
//      does things in a random order and you want to know (in the end) which order it used.
//      You can, ofcourse, write this to a (log)file.
//      Don't forget to use y_breadcrumb_reset() to clear the parameter at the start of the script.
// @author: Raymond de Jongh
// Example:
//        y_breadcrumb_reset();    // clean the breadcrumb-variable. (previous data in {breadcrumb} is deleted.
//        y_breadcrumb("start");
//        .... some code....
//        y_breadcrumb("processing data")
//        ... some code ....
//        y_breadcrumb("finished")
//      The result is that {breadcrumb} contains "start;processing data;finished"
// --------------------------------------------------------------------------------------------------
void y_breadcrumb(char *breadcrumb)
{
    lr_message("---------------------------------------------------------------------------------");

    if ((strcmp(lr_eval_string("{breadcrumb}"), "{breadcrumb}") == 0) || ((strcmp(breadcrumb, "") == 0)))
    {
        lr_save_string("", "breadcrumb");
        lr_save_string(breadcrumb, "y_breadcrumb_temp");
        lr_save_string(lr_eval_string("{y_breadcrumb_temp}"), "breadcrumb");
    }
    else
    {
        lr_save_string(breadcrumb, "y_breadcrumb_temp");
        lr_save_string(lr_eval_string("{breadcrumb};{y_breadcrumb_temp}"), "breadcrumb");
    }
}
Exemple #4
0
// --------------------------------------------------------------------------------------------------
// y_write_to_file()
//       writes content (a string) to a file.
// @author: Raymond de Jongh
// Example:
//      y_write_to_file("c:\\test.txt", "Write this to a file!");
// --------------------------------------------------------------------------------------------------
int y_write_to_file(char *filename, char *content)
{
   long file;
   int result;

   lr_message("LOGGING: %s", content);

   if ((file = fopen(filename, "at")) == NULL)
   { 
       lr_error_message ("Cannot write to file >>%s<<", filename); 
       return -1;             // failed to open file...
   } 
   if (result = fprintf(file, "%s\n", content) <0)
   {
       return result;        // failed to write to file...
   }

   if (result = fclose(file)!=0)
   {
       return result;        // failed to close file...
   }

   return 0;                // everything worked great!
}
Exemple #5
0
MySQLTemplate()
{
	int rc = 0;

    MYSQL *db_connection; 
    MYSQL_RES *query_result; 
    MYSQL_ROW result_row; 
    
    char *server = "localhost";
    char *user = "******";
    char *password = "******"; 
    char *database = "LRDB";
    int port = 3306; // default MySQL port

	//static char *server_options[] = { "mysql_test", "--defaults-file=my.cnf" };
	//int num_elements = sizeof(server_options)/ sizeof(char *);
    
    lr_whoami(&vuser_id, &vuser_group, &scid);
	lr_message( "Group: %s, vuser id: %d, scenario id %d", vuser_group, vuser_id, scid);

	if (vuser_id == -1) {
		vuser_id = 1;
	}

	rc = lr_load_dll("C:\\Program Files\\MySQL\\MySQL Server 5.0\\lib\\opt\\libmysql.dll");
    // You should be able to find the MySQL DLL somewhere in your MySQL install directory.
    if (rc != 0) {
        lr_error_message("Could not load libmysql.dll");
        lr_abort();
    }
    
    // Allocate and initialise a new MySQL object
    db_connection = mysql_init(NULL);
    if (db_connection == NULL) {
        lr_error_message("Insufficient memory");
        return -1;
    }

	  // Connect to the database
    if (mysql_real_connect(db_connection, server, user, password, database, port, NULL, 0) == NULL) {
		lr_error_message("error on connect: %s\n", mysql_error(db_connection));
		return -1;
	}

    if (mysql_query(db_connection, "SELECT * FROM LATLogin;")!= 0) {
		lr_error_message("error on query: %s\n", mysql_error(db_connection));
		return -1;
	}

	if ((query_result = mysql_store_result(db_connection)) == NULL) {
		lr_error_message("error on store: %s\n", mysql_error(db_connection));
		return -1;
	}

    while (result_row = mysql_fetch_row(query_result)) {
		lr_output_message("%s - %s", result_row[0]);
	}
	mysql_free_result(query_result);
	

    // Free the MySQL object created by mysql_init
    mysql_close(db_connection);
	mysql_server_end();

	return 0;
}