Esempio n. 1
0
void test(const char* input, const char* expectedCompressed) {
  char* compressed = compressString(input);
  if (strcmp(compressed, expectedCompressed) == 0) {
    printf("PASS: orig len %lu; compressed len %lu\n", strlen(input), strlen(compressed));
  } else {
    printf("FAIL: got %s; expected %s\n", compressed, expectedCompressed);
  }
  free(compressed);
}
Esempio n. 2
0
Status TLSTransport::sendRequest(const std::string& params, bool compress) {
  if (destination_.find("https://") == std::string::npos) {
    return Status(1, "Cannot create TLS request for non-HTTPS protocol URI");
  }

  auto client = getClient();
  http::client::request r(destination_);
  decorateRequest(r);
  if (compress) {
    // Later, when posting/putting, the data will be optionally compressed.
    r << boost::network::header("Content-Encoding", "gzip");
  }

  // Allow request calls to override the default HTTP POST verb.
  HTTPVerb verb = HTTP_POST;
  if (options_.count("verb") > 0) {
    verb = (HTTPVerb)options_.get<int>("verb", HTTP_POST);
  }

  VLOG(1) << "TLS/HTTPS " << ((verb == HTTP_POST) ? "POST" : "PUT")
          << " request to URI: " << destination_;
  if (FLAGS_verbose && FLAGS_tls_dump) {
    fprintf(stdout, "%s\n", params.c_str());
  }

  try {
    if (verb == HTTP_POST) {
      response_ = client.post(r, (compress) ? compressString(params) : params);
    } else {
      response_ = client.put(r, (compress) ? compressString(params) : params);
    }

    const auto& response_body = body(response_);
    if (FLAGS_verbose && FLAGS_tls_dump) {
      fprintf(stdout, "%s\n", std::string(response_body).c_str());
    }
    response_status_ =
        serializer_->deserialize(response_body, response_params_);
  } catch (const std::exception& e) {
    return Status((tlsFailure(e.what())) ? 2 : 1,
                  std::string("Request error: ") + e.what());
  }
  return response_status_;
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
	FILE *pFile = fopen("1.5.in", "r");
    int len;
    char line[MAXN];

    while (fgets(line, MAXN, pFile) != NULL)
    {
        len = strlen(line);
        line[len-2] = '\0';//replaced '\n'
        compressString(line);
        printf ("%s\n", line);
    }
    
	return 0;
}
Esempio n. 4
0
int main (){

	char * testString = "HHHello World";
/*
	if(checkAllUniqueChar(testString) == 0 ){

		printf("String Contains Duplicate Characters\n");
	}
	else
	{
		printf("String Contains All Unique Characters\n");
	}
*/
	compressString(testString);
	//printf("%s\n", testString);
	return 0;
}
Esempio n. 5
0
int main(){
    std::string str = "abbcccccde";
//    std::string str = "aa";
    std::cout << str << " after compression: " << compressString(str) << std::endl;
    return 0;
}
asynStatus FileList::updateList()
{
	char dirBase[INPUT_WAVEFORM_LIM];
	char search[INPUT_WAVEFORM_LIM];
	int caseSense;
	std::list<std::string> files;
	int status = asynSuccess;
	std::string out;

	lock();

	//get all files in directory
	status |= getStringParam(P_DirBase, INPUT_WAVEFORM_LIM, dirBase);

	if (getFileList(dirBase, files) == -1)
	{
		std::cerr << "Directory not found: " << dirBase << std::endl;
		unlock();
		return asynError;
	}

	//search files
	status |= getStringParam(P_Search, INPUT_WAVEFORM_LIM, search);

	status |= getIntegerParam(P_CaseSensitive, &caseSense);

	if (caseSense == 0)
	{
		status |= filterList(files, std::string("(?i)").append(search));
	} else {
		status |= filterList(files, search);
	}
	
	if (m_fullPath)
	{
	    std::string dir_prefix = std::string(dirBase) + "/";
	    std::replace(dir_prefix.begin(), dir_prefix.end(), '\\', '/');
		for(std::list<std::string>::iterator it = files.begin(); it != files.end(); ++it)
		{
		    it->insert(0, dir_prefix);
		}
	}
	
	//add appropriate files to PV
	std::string tOut = json_list_to_array(files);
	status |= compressString(tOut, out);

	if (out.size() < OUT_CHAR_LIM)
		std::copy(out.begin(), out.end(), pJSONOut_);
	else
		std::cerr << "File list too long: " << out.size() << std::endl;

	status |= setStringParam(P_JSONOutArr, pJSONOut_);

	/* Do callbacks so higher layers see any changes */
	status |= (asynStatus)callParamCallbacks();

	unlock();

	return (asynStatus)status;
}
// jcaput pv [value1] [value2] [value3]
// if no value, uses stdin
int main(int argc, char* argv[])
{
    std::string comp_str, str;
	std::list<std::string> items;
	const char* delims = " \t\r\n";
	int opt;
	long double waittime = 1.0f;
	bool single_element = false;
	bool verbose = false;
	bool no_whitespace = false;
    while ((opt = getopt(argc, argv, "1vhiw:s:")) != -1) 
	{
        switch (opt) {
        case 'h':             
            usage();
            return 0;
			
        case 'v':              
            verbose = true;
            break;

		case 's':              
            delims = strdup(optarg);
            break;
			
		case '1':              
            single_element = true;
            break;
		
		case 'i':
			no_whitespace = true;
			break;
		
		case 'w':
			waittime = atof(optarg);
			break;
			
		default:
			break;
		}
	}
	int nargs = argc - optind;
	const char* pv = argv[optind];
	if (nargs < 1)
	{
	    usage();
		return -1;
	}
	if (nargs == 1)
	{
	    std::getline(std::cin, str);
		char* buffer = strdup(str.c_str());
		char* saveptr;
		const char* item = epicsStrtok_r(buffer, delims, &saveptr);
		while( item != NULL )
		{
			items.push_back(item);
		    item = epicsStrtok_r(NULL, delims, &saveptr); 
		}
	}
	else
	{
		if (!no_whitespace)
		{
			for(int i=optind+1; i<argc; ++i)
			{
				items.push_back(argv[i]);
			}
		} else {
			std::string input = "";
			for(int i=optind+1; i<argc; ++i)
			{
				input.append(argv[i]);
				input.append(" ");
			}
			items.push_back(input);
		}
	}
	std::string json;
	if (!single_element && (items.size() == 1))
	{
	    json = "\"" + items.front() + "\"";
	}
	else
	{
	    json = json_list_to_array(items);
	}
	int ret = compressString(json, comp_str);
	if (ret == 0)
	{
	    std::ostringstream command;
	    command <<  "caput -S -w" << waittime <<  " " << pv << " " << comp_str;
		if (verbose)
		{
			std::cout << "jcaput: JSON: " << json << std::endl;
			std::cout << "jcaput: " << command.str() << std::endl;
		}
	    system(command.str().c_str());
    }		
	return ret;
}
void isisdaeDriver::pollerThread2()
{
    static const char* functionName = "isisdaePoller2";
	std::map<std::string, DAEValue> values;
    unsigned long counter = 0;
    double delay = 2.0;  
    long this_rf = 0, this_gf = 0, last_rf = 0, last_gf = 0;
    bool check_settings;
    std::string daeSettings;
    std::string tcbSettings, tcbSettingComp;
    std::string hardwarePeriodsSettings;
    std::string updateSettings;
    std::string vetoStatus;

    lock();
	while(true)
	{
        unlock();
		epicsThreadSleep(delay);
		lock();
        if (m_inStateTrans)   // do nothing if in state transition
        {
            continue;
        }
        check_settings = ( (counter == 0) || (m_RunStatus == RS_SETUP && counter % 2 == 0) || (counter % 10 == 0) );
        try
        {
            m_iface->getRunDataFromDAE(values);
            m_iface->getVetoStatus(vetoStatus);
            if (check_settings)
            {
                m_iface->getDAESettingsXML(daeSettings);
                m_iface->getTCBSettingsXML(tcbSettings);
                m_iface->getHardwarePeriodsSettingsXML(hardwarePeriodsSettings);
                m_iface->getUpdateSettingsXML(updateSettings);
            }
            this_gf = m_iface->getGoodFrames();        
		    this_rf = m_iface->getRawFrames();
        }
        catch(const std::exception& ex)
        {
            std::cerr << ex.what() << std::endl;
            continue;
        }
        if (this_rf > last_rf)
        {
            m_vetopc = 100.0 * (1.0 - static_cast<double>(this_gf - last_gf) / static_cast<double>(this_rf - last_rf));
        }
        else
        {
            m_vetopc = 0.0;
        }
        last_rf = this_rf;
        last_gf = this_gf;
        setStringParam(P_RunTitle, values["RunTitle"]); 
        setStringParam(P_RBNumber, values["RBNumber"]); 
		const char* rn = values["RunNumber"];
        setStringParam(P_RunNumber, rn);
        setIntegerParam(P_IRunNumber, atol(rn));
        setStringParam(P_InstName, values["InstName"]);
        setStringParam(P_UserName, values["UserName"]);
        setStringParam(P_UserTelephone, values["UserTelephone"]);
        setStringParam(P_StartTime, values["StartTime"]);
        setDoubleParam(P_NPRatio, values["N/P Ratio"]);
        setStringParam(P_ISISCycle, values["ISISCycle"]);
        setStringParam(P_DAETimingSource, values["DAETimingSource"]);
        setStringParam(P_PeriodType, values["Period Type"]);
        
        setIntegerParam(P_RawFramesPeriod, values["RawFramesPeriod"]);
        setIntegerParam(P_GoodFramesPeriod, values["GoodFramesPeriod"]);
        
        setIntegerParam(P_RunDurationTotal, values["RunDurationTotal"]);
        setIntegerParam(P_RunDurationPeriod, values["RunDurationPeriod"]);
        setIntegerParam(P_NumTimeChannels, values["NumberOfTimeChannels"]);
        setIntegerParam(P_NumPeriods, values["NumberOfPeriods"]);
        setIntegerParam(P_DAEMemoryUsed, values["DAEMemoryUsed"]);
        
        setIntegerParam(P_Period, values["CurrentPeriod"]);
        setIntegerParam(P_NumSpectra, values["NumberOfSpectra"]);
        setIntegerParam(P_MonitorCounts, values["MonitorCounts"]);
        setIntegerParam(P_PeriodSequence, values["PeriodSequence"]);
        setIntegerParam(P_MonitorSpectrum, values["MonitorSpectrum"]);
        
        setDoubleParam(P_BeamCurrent, values["BeamCurrent"]);
        setDoubleParam(P_TotalUAmps, values["TotalUAmps"]);
        setDoubleParam(P_MonitorFrom, values["MonitorFrom"]);
        setDoubleParam(P_MonitorTo, values["MonitorTo"]);
        setDoubleParam(P_TotalDaeCounts, values["TotalDAECounts"]);
        setDoubleParam(P_CountRate, values["CountRate"]);
        setDoubleParam(P_EventModeFraction, values["EventModeCardFraction"]);
        setDoubleParam(P_VetoPC, m_vetopc);
        
        setStringParam(P_VetoStatus, vetoStatus.c_str() );
        if (check_settings) 
        {
            setStringParam(P_DAESettings, daeSettings.c_str());
		    if (compressString(tcbSettings, tcbSettingComp) == 0)
		    {
                setStringParam(P_TCBSettings, tcbSettingComp.c_str());
		    }
            setStringParam(P_HardwarePeriodsSettings, hardwarePeriodsSettings.c_str() );
            setStringParam(P_UpdateSettings, updateSettings.c_str() );
			
			std::string val;
			getDAEXML(daeSettings, "/Cluster/String[Name='Wiring Table']/Val", val);
			setStringParam(P_wiringTableFile, val.c_str());
			getDAEXML(daeSettings, "/Cluster/String[Name='Detector Table']/Val", val);
			setStringParam(P_detectorTableFile, val.c_str());
			getDAEXML(daeSettings, "/Cluster/String[Name='Spectra Table']/Val", val);
			setStringParam(P_spectraTableFile, val.c_str());
			getDAEXML(tcbSettings, "/Cluster/String[Name='Time Channel File']/Val", val);
			setStringParam(P_tcbFile, val.c_str());
			getDAEXML(hardwarePeriodsSettings, "/Cluster/String[Name='Period File']/Val", val);
			setStringParam(P_periodsFile, val.c_str());
        }          
		std::list<std::string> messages;
		std::string all_msgs;
		m_iface->getAsyncMessages(messages);
		for(std::list<std::string>::const_iterator it=messages.begin(); it != messages.end(); ++it)
		{
			std::string mess_ts;
			isisdaeInterface::stripTimeStamp(it->c_str(), mess_ts);
		    all_msgs.append(mess_ts);
			errlogSevPrintf(errlogInfo, "%s", mess_ts.c_str());
		}
		if (all_msgs.size() > 0)
		{
            setStringParam(P_AllMsgs, all_msgs.c_str());
		}
		messages.clear();
		callParamCallbacks();        
        ++counter;
	}
}	
Esempio n. 9
0
 Status sendRequest(const std::string& params, bool compress) override {
   // Optionally compress.
   response_status_ = Status(0, (compress) ? compressString(params) : params);
   return response_status_;
 }