Exemplo n.º 1
0
int set_gen_QR_attribute(){

	   LPCSTR_SaveImageYN = lr_get_attrib_string("SaveImageYN"); // from run-time settings or command line.
 	if(LPCSTR_SaveImageYN==NULL){
	   LPCSTR_SaveImageYN=SaveImageYN_default; // ="N"; as N=No default.
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"SaveImageYN\" not specified. QR image files NOT generated from short URLs by default. [in vuser_init]"
					,LPCSTR_SaveImageYN 
					);
			wi_stopPrinting();
	}else{
		if( stricmp("Y",LPCSTR_SaveImageYN ) == FOUND ){ // Run-time Attribute "SaveImageYN" or command line option "-SaveImageYN"
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"SaveImageYN\"=%s. QR image files generated from short URLs. [in vuser_init]"
					,LPCSTR_SaveImageYN 
					);
			wi_stopPrinting();
		}else{
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"SaveImageYN\"=%s. QR image files NOT generated from short URLs. [in vuser_init]"
					,LPCSTR_SaveImageYN 
					);
			wi_stopPrinting();
		}
	}
	
	return LR_PASS;
} // set_gen_QR_attribute()
Exemplo n.º 2
0
int vi_set_VTS3(){

	int rc=LR_PASS;
	
	// Using VTS3 (Virtual Table Service version 3) available since LR 11.52+:
	// See blog by its developer at http://h30499.www3.hp.com/t5/HP-LoadRunner-and-Performance/The-New-Virtual-Table-Server-VTS-in-LoadRunner-11-52/ba-p/6069435#.Ukt79rHnb4Y
	// HP Support article at http://support.openview.hp.com/selfsolve/document/KM305130

       LPCSTR_VTS_Host = lr_get_attrib_string("VTS_Host"); // from Run-time settings Attributes or command line.
 	if(LPCSTR_VTS_Host==NULL){                 // Not specified in Run-Time Settings Attributes or command line.
 	          VTS_Host_string="localhost"; // VTS_Host_default; // such as "localhost"; 

			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"VTS_Host\" not specified in command-line or run-time settings. Default to \"%s\"."
					,VTS_Host_string
					);
			wi_stopPrinting();
    }else{
		sprintf( VTS_Host_string ,"%s",LPCSTR_VTS_Host);
	} // if(LPCSTR_VTS_Host==NULL)
       

       LPCSTR_VTS_Port = lr_get_attrib_string("VTS_Port"); // from Run-time settings Attributes or command line.
 	if(LPCSTR_VTS_Port==NULL){             // Not specified in Run-Time Settings Attributes or command line.
 	             nPort=8787; // nVTS_Port_default; // such as 8787 or 8888;
		    wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"VTS_Port\" not specified in command-line or run-time settings. Default to \"%d\"."
					,nPort 
					);
			wi_stopPrinting();
    }else{
     	nPort = atoi(LPCSTR_VTS_Port); 
	} // if(LPCSTR_VTS_Port==NULL)

    /// Connect using LoadRunner native functions:
 		pvci = vtc_connect( VTS_Host_string , nPort , VTOPT_KEEP_ALIVE ); // VTS_Host_string
	if( pvci <= 0){
	    wi_startPrintingDebug();
		lr_error_message(">> VTS pvci=%d (non-zero).", pvci);
		wi_stopPrinting();
	}else{
		rc = vtc_get_last_error(pvci);
		if( rc != LR_PASS ) {
		    wi_startPrintingDebug();
			lr_error_message(">> rc from vtc_get_last_error(pvci)=%d for VTC connection to %s port .", rc, VTS_Host_string,nPort);
			wi_stopPrinting();
			return LR_FAIL; // FAIL
		}

		// Count rows in VTS table:
		vtc_column_size(pvci, "web", &nVTS_row_count);
		wi_startPrintingInfo();
		lr_output_message(">> nVTS_row_count=%d.", nVTS_row_count);
		wi_stopPrinting();
	}

	return rc;
} // vi_set_VTS3()
Exemplo n.º 3
0
int wi_set_unique_id(){
	int rc=LR_PASS;
	char*			my_controller_name;
	char*			my_host; // host_name of load generator (injector):
	int 			iScenarioID;
	char* 			vuser_group;
	int 			iVuserID; // -1 if run in VuGen.
	char* 			sVuserID[32]; // from lr_get_vuser_ip()
//	char 			my_unique_id[64]=""; // defined as global variable.
	int              vuser_pid=0; // Windows Process ID
	
	my_controller_name = lr_get_master_host_name(); 
	my_host = lr_get_host_name();
	vuser_pid = wi_get_vuser_pid();

	lr_whoami(&iVuserID, &vuser_group, &iScenarioID); // lr_whoami returns void by design (no rc).

	// NOTE: When run in VuGen: Controller=None, host=%MACHINENAME%, ScenarioID=0, vuser_group=None, iVuserID=-1.
  	wi_startPrintingInfo();
	lr_output_message(">> Controller=%s, Host=%s, ScenarioID=%d, Group=%s, Vuser=%d, PID=%d." 
  	                  ,my_controller_name ,my_host ,iScenarioID, vuser_group ,iVuserID, vuser_pid );
	wi_stopPrinting();
	
	sprintf( global_unique_id,"C%s.H%d.S%s.G%s.U%d.P%d"
			,my_controller_name
			,my_host
			,iScenarioID
			,vuser_group
			,iVuserID
			,vuser_pid
			);

	return rc;
} // wi_set_unique_id
Exemplo n.º 4
0
int vi_set_Verbosity_attribute(){

	   LPCSTR_Verbosity = lr_get_attrib_string("Verbosity"); // from Run-time settings Attributes or command line.
	if(LPCSTR_Verbosity==NULL){                 // Not specified in Run-Time Settings Attributes or command line.
            iVerbosity=iVerbosity_default; // =default.
		    wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"Verbosity\" not specified in command-line or run-time settings. Default to \"%d\"."
					,iVerbosity
					);
			wi_stopPrinting();
		// NOTE: Don't return LR_FAIL; // fail here because default can be used.
	}else{
		iVerbosity=atoi(LPCSTR_Verbosity);
	} // if(LPCSTR_Verbosity==NULL)

	// TODO: 23. Set each web_set_max_html_param_len based on the largest individual server response detrermined from initial runs.	   
	if( iVerbosity == 1 ){
	    web_set_max_html_param_len("10240"); 
	}else
	if( iVerbosity == 2 ){
	    web_set_max_html_param_len("10240");
	}else
	if( iVerbosity == 3 ){
	    web_set_max_html_param_len("10240");
	}else
	if( iVerbosity == 4 ){
	    web_set_max_html_param_len("10240");
	}else
	if( iVerbosity == 5 ){
	    web_set_max_html_param_len("20240");
	}else{
	   	iVerbosity=iVerbosity_default; // =default.
		    wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"Verbosity\" not specified in command-line or run-time settings. Default to \"%d\"."
					,iVerbosity
					);
			wi_stopPrinting();

			wi_startPrintingError();
		    lr_output_message(">> Attribute \"Verbosity\" not recognized as valid value."
					,iVerbosity
					);
			wi_stopPrinting();
	}
	return LR_PASS;
} // vi_set_Verbosity_attribute()
Exemplo n.º 5
0
vi_set_RunType_attribute(){

	LPCSTR_RunType = lr_get_attrib_string("RunType"); // from run-time settings Attributes or command line.
 	if(LPCSTR_RunType==NULL){ // Not specified in Run-Time Settings Attributes or command line.
	   LPCSTR_RunType="All"; // =default.
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"RunType\" not specified in command-line or run-time settings. Default to \"%s\"."
					,LPCSTR_RunType 
					);
			wi_stopPrinting();
	}else{ // Ensure only acceptable values were input:
		if( stricmp("All",LPCSTR_RunType ) == FOUND ){ // Run-time Attribute "RunType" or command line option "-RunType"
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"RunType\"=%s."
					,LPCSTR_RunType 
					);
			wi_stopPrinting();
       	}else
		if( stricmp("NoOp",LPCSTR_RunType ) == FOUND ){ // Run-time Attribute "RunType" or command line option "-RunType"
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"RunType\"=%s for no operation."
					,LPCSTR_RunType 
					);
			wi_stopPrinting();
		}else{
			wi_startPrintingError();
		    lr_output_message(">> Attribute \"RunType\"=%s not valid. lr_exit() stopping script execution."
					,LPCSTR_RunType 
					);
			wi_stopPrinting();
			lr_exit(LR_EXIT_VUSER,LR_FAIL);
		}
	} // if(LPCSTR_RunType==NULL)

	return LR_PASS;
} // vi_set_RunType_attribute()
Exemplo n.º 6
0
wi_show_user_agent(){
	// This makes use of the request_header captured by this invoked before a call:
	//    web_save_header(REQUEST,"request_header");
	// Which only needs to be done once if the client Agent String does not change during a run.
	
	char * headers = lr_eval_string("{request_header}");
 
 	lr_save_param_regexp(headers,
        strlen(headers),
   		"RegExp=User-Agent: (.+)\\r\\n",
   		"ResultParam=userAgent",
   		LAST );

	// {userAgent} is one of the run conditions shown one time for whole run:
		wi_startPrintingInfo();
 	lr_output_message(">> {userAgent}=%s.", lr_eval_string("{userAgent}"));
	// TODO: Intrepret raw agent string to summarize the browser name and version.
		wi_resetPrinting();

	return 0;
}
Exemplo n.º 7
0
get_google_short_url_qrcode(){
	int rc=0;
		char            strFileName[256]; // largest size of file.
		char           *szBuf;
		unsigned long   nLength;

	if( stricmp("Y",LPCSTR_SaveImageYN ) == FOUND ){ // Run-time Attribute "SaveImageYN" or command line option "-SaveImageYN"
	   // continue if SaveImageYN was specified with Y
	}else{
		return LR_PASS;
	}

		set_pShortHostKey_from_url( lr_eval_string("{pShortURL}") ); // from get_google_short_url()
			//wi_startPrintingTrace();
			//lr_output_message(">> pShortHostKey=\"%s\"." ,lr_eval_string("{pShortHostKey}") );
			//wi_stopPrinting();

		// For shortened URL http://goo.gl/AC4IW", details are at http://goo.gl/#analytics/goo.gl/AC4IW/all_time
		// {pShortHostKey}=AC4IW in example: URL http://goo.gl/AC4IW.qr redirects to 
		// The QR code impage at http://chart.googleapis.com/chart?cht=qr&chs=100x100&choe=UTF-8&chld=H|0&chl=http://goo.gl/AC4IW
		web_reg_save_param_ex("ParamName=pImage", "LB=\r\n\r\n", "RB=\"",  "Notfound=warning", LAST); // The \r\n\r\n is to begin capture after the two blank lines between HTTP header and body.
		web_reg_save_param_ex("ParamName=pImage_len", "LB=Content-Length: ", "Notfound=warning", "RB=\r\n", LAST);

		sprintf(       tempString1, "%s_3image", lr_eval_string("{pTransSequence}") );
		lr_save_string(tempString1,"pTransName");
	    wi_start_transaction();
	    
    // This URL was obtained from the DNS-level redirect in the HTML header in response to request for .qr, such as:
    // The document has moved <A 
    //        HREF="http://chart.googleapis.com/chart?cht=qr&amp;chs=150x150&amp;choe=UTF-8&amp;chld=H&amp;chl=http://goo.gl/x6wUIS">here</A>.\n
    	// &amp; needs to be coverted to & character in URLs.
    	
		// WARNING: The 150x150 in this URL may change over time as more characters are needed for uniqueness.
		// Previously,  100x100 was being returned:
		//    "URL={pShortURL}.qr",
		web_url("imagefile",
	        "URL=http://chart.googleapis.com/chart?cht=qr&chs=150x150&choe=UTF-8&chld=H&chl={pShortURL}",
	        "Resource=1",
	        "RecContentType=image/png",
	        "Snapshot=t1.inf",
	        LAST);
		// FIXME: File created has black box at bottom.
	
	    rc = wi_end_transaction();

		// strFileName=wi_define_FileName():
		lr_save_datetime("%Y%m%d%H%M%S", DATE_NOW, "pYMDHMS"); // YYMMDDHHMMSS (12 char), no micro seconds
		sprintf(strFileName, "%s%s_%d_T%s_%s_%s.png"
		        ,lr_eval_string("{pImageFilePath}")
				,global_unique_id
				,iActionIterations
				,lr_eval_string("{pYMDHMS}")
		        ,lr_eval_string("{pShortHostKey}")
		        ,lr_eval_string("{pImage_len}")
		       );

		lr_eval_string_ext("{pImage}", strlen("{pImage}"), &szBuf, &nLength, 0, 0, -1);
		// lr_eval_string_ext( in_str, in_len,    pointer out_str, out_len, Reserved for future use. 
		if( nLength <= 0 ){
			lr_error_message(">> No image returned for %s.",strFileName);
		}else{
			if( wi_WriteDataToFile(strFileName, szBuf, nLength) == LR_PASS ){
				wi_startPrintingInfo();
				lr_output_message(">> QRcode_image file created at \"%s\".",strFileName);
				wi_stopPrinting();
			   	// TODO: 23. Remember after runs to clear out the files to an archive filer.
			}else{
				wi_startPrintingError();
				lr_error_message(">>> QRcode_image file NOT created at \"%s\".",strFileName);
				wi_stopPrinting();
			}
		}
	return rc;
} // retrieve_pShortURL_qrcode()
Exemplo n.º 8
0
get_google_short_url(){
    
	// About this call: https://developers.google.com/url-shortener/v1/getting_started
	// Forum on this:   https://groups.google.com/forum/#!forum/google-url-shortener

	int rc=LR_PASS;
	int	bURLtoShorten_success=LR_PASS;

	rc=get_long_url_to_shorten();
	if( rc != LR_PASS ){ return rc; } // No input data to process.
	
	// Define the URL Shortener API Scope to Google:
	lr_save_string("https://www.googleapis.com/auth/urlshortener","pServiceScope");
					// Other Google API FAQ scopes: https://developers.google.com/gdata/faq#AuthScopes

	sprintf(       tempString1, "%s_access", lr_eval_string("{pTransSequence}") );
	lr_save_string(tempString1,"pTransName");
	rc=get_google_access_token();
	if( rc != LR_PASS ){ return rc; } // No input data to process.

	if( stricmp("NoOp",LPCSTR_RunType ) == FOUND ){ // "NoOp" or "NOOP" specified in Run-time Attribute "RunType" or command line option "-RunType".
		wi_startPrintingInfo();
		lr_output_message(">> RunType=\"%s. JWT=%s."
				,LPCSTR_SaveImageYN
				,lr_eval_string("{pJWTAssertion}")
				);
		wi_stopPrinting();
		return LR_PASS;
	}

		// Using parameter file "URLtoShorten.dat" containing parmeter "pURLtoShorten":
		web_reg_save_param_ex("ParamName=pLongURL","LB=\"longUrl\": \"","RB=\"",SEARCH_FILTERS,"Scope=body",LAST);	// the long  URL input to API server.
		web_reg_save_param_ex("ParamName=pShortURL","LB=\"id\": \"","RB=\"",SEARCH_FILTERS,"Scope=body",LAST); 		// the short URL output from server.

		// WARNING: Google does not check if there is a short code already generated for the URL before generating another one (which bit.ly does).
		web_add_header("Authorization", lr_eval_string("Bearer {pAccessToken}"));
	    web_add_header("Content-Type", "application/json");

		// TODO: 18. If you want to, change the transaction name suffix for shortenend url requests.
		sprintf( 	   tempString1, "%s_2shorturl", lr_eval_string("{pTransSequence}") );
		lr_save_string(tempString1,"pTransName");
	    wi_start_transaction();
	    web_custom_request("Shorten",
                       "URL=https://www.googleapis.com/urlshortener/v1/url",
                       "Method=POST",
                       "Body={\"longUrl\": \"{pURLtoShorten}\"}",
                       LAST);    
					// This code is the C equivalent of the Java at https://developers.google.com/api-client-library/java/apis/urlshortener/v1    
		// Google docs say output should look like this:
		//	{
		//		"kind": "urlshortener#url",\n
		//		"id": "http://goo.gl/jQVbkn",\n
		//		"longUrl": "http://www.hp.com/"\n
		//	}

		rc = wi_end_transaction();

		if( rc == LR_PASS ){
			bURLtoShorten_success=LR_PASS;
			nURLtoShorten_done++; // increment.
		}
		
		wi_startPrintingDebug();
	    lr_output_message(">> done=%d LongURL=%s to pShortURL=%s, seconds=%8.2f under %s."
		        ,nURLtoShorten_done 
				,lr_eval_string("{pLongURL}")
				,lr_eval_string("{pShortURL}")
				,floatHttpMilliseconds
				,lr_eval_string("{pRunConditions}")
				);
		wi_stopPrinting();
	
	#ifdef USE_VTS
	update_shorturl_in_VTS();
	#endif // USE_VTS

	#ifdef GEN_QR
	if( bURLtoShorten_success == LR_PASS ){
		// TODO: 19. Customize your own transaction name for calling get_google_short_url_qrcode().
		lr_save_string("get_google_short_url_qrcode","pTransName"); 
		get_google_short_url_qrcode(); // using pShortURL and pImageFilePath, depending on command flag LPCSTR_SaveImageYN.
	}
	#endif // GEN_QR

	return rc;
} // get_google_short_url()
Exemplo n.º 9
0
vi_set_URLSource_attribute(){

	int rc=LR_PASS;
	
	   LPCSTR_URLSource = lr_get_attrib_string("URLSource"); // from run-time settings Attributes or command line "-URLSource".
 	if(LPCSTR_URLSource==NULL){ // Not specified in Run-Time Settings Attributes or command line.
		     iURLSource_setting=iURLSource_default;

			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"URLSource\" not specified in command-line or run-time settings. Default to \"%d\".", iURLSource_setting );
			wi_stopPrinting();
	}else{ // Ensure only acceptable values were input:
		if( stricmp("All",iURLSource_setting ) == FOUND ){ // Run-time Attribute "URLSource" or command line option "-URLSource"
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"URLSource\"=%s."
					,iURLSource_setting
					);
			wi_stopPrinting();
       	}else
		if( iURLSource_setting == 1 ){
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"URLSource\"=%s for using file URLtoShorten.dat in script folder." ,iURLSource_setting );
			wi_stopPrinting();

		#ifdef USE_VTS
       	}else
		if( iURLSource_setting == 2 ){
			wi_startPrintingInfo();
		    lr_output_message(">> Attribute \"URLSource\"=%s for using VTS." ,iURLSource_setting);
			wi_stopPrinting();
		#endif // USE_VTS
		
		}else{
			wi_startPrintingError();
		    lr_output_message(">> Attribute \"URLSource\"=%s not valid. lr_exit() stopping script execution." ,iURLSource_setting );
			wi_stopPrinting();
			lr_exit(LR_EXIT_VUSER,LR_FAIL);
		}
	} // if(iURLSource_setting==NULL)

	// Regardless of iURLSource_setting selection,
	// define number of records in file (for all iURLSource_setting options because this is the fall-back):
	    nURLtoShorten_file_recs = vi_set_pURLtoShorten_file_recs();
	if( nURLtoShorten_file_recs == -1 ){
		lr_error_message("> vi_set_pURLtoShorten_file_recs() nURLtoShorten_file_recs=%d",nURLtoShorten_file_recs);
	}else{
	  	wi_startPrintingInfo();
		lr_output_message(">> nURLtoShorten_file_recs=%d.", nURLtoShorten_file_recs);
		wi_stopPrinting();
	}

	#ifdef USE_VTS
    if( iURLSource_setting == 2 ){
	    rc=vi_set_VTS3(); // Find the count of records in VTS table into nVTS_row_count.
		if( rc != LR_PASS ){
	    	// TODO: 12. If you prefer, if VTS cannot be used, change coding to error out instead of falling back if records were found earlier:
	    	if( nURLtoShorten_file_recs > 0 ){ // if records were found earlier?
				iURLSource_setting = 1; // use local data source
				
				wi_startPrintingInfo();
				lr_output_message(">> rc=%d fall-back to local data source with nURLtoShorten_file_recs=%f when iURLSource_setting=%d.", rc, nURLtoShorten_file_recs, iURLSource_setting);
				wi_stopPrinting();
			}
	    }else{
			// Add column "shorturl" to VTS for holding output from Google API calls:
			rc = vtc_create_column (pvci, "shorturl", &status); // status=1 is success.
				wi_startPrintingDebug();
				lr_output_message(">> rc=%d from vi_set_VTS3() with status=%d (should=1) when iURLSource_setting=%d.", rc, status, iURLSource_setting);
				wi_stopPrinting();
			if( status == 1 ){
				iUpdate_shorturl_in_VTS = 1; // 1=Yes

				wi_startPrintingInfo();
				lr_output_message(">> rc=%d with status=%d (should=1), so iUpdate_shorturl_in_VTS =%d (1=1Yes).", rc, status, iUpdate_shorturl_in_VTS );
				wi_stopPrinting();
			}else{
				iUpdate_shorturl_in_VTS = 0; // 0=No

				wi_startPrintingInfo();
				lr_output_message(">> rc=%d with status=%d (should=1), so iUpdate_shorturl_in_VTS =%d (0=NO).", rc, status, iUpdate_shorturl_in_VTS );
				wi_stopPrinting();
			}
	    }
    }
	#endif // USE_VTS

	return LR_PASS;
} // vi_set_URLSource_attribute()