Ejemplo n.º 1
0
bool
cgicc::FormFile::operator== (const FormFile& file) 		const
{
  return (stringsAreEqual(fName, file.fName) && 
	  stringsAreEqual(fFilename, file.fFilename) &&
	  stringsAreEqual(fDataType, file.fDataType));
}
Ejemplo n.º 2
0
void CCocoaPowerSyscall::OSPowerSourceCallBack(void *refcon)
{
#if !defined(TARGET_DARWIN_IOS)
  // Called whenever any power source is added, removed, or changes. 
  // When on battery, we get called periodically as battery level changes.
  CCocoaAutoPool autopool;
  CCocoaPowerSyscall  *ctx = (CCocoaPowerSyscall*)refcon;

  CFTypeRef power_sources_info = IOPSCopyPowerSourcesInfo();
  CFArrayRef power_sources_list = IOPSCopyPowerSourcesList(power_sources_info);

  for (int i = 0; i < CFArrayGetCount(power_sources_list); i++)
  {
		CFTypeRef power_source;
		CFDictionaryRef description;

		power_source = CFArrayGetValueAtIndex(power_sources_list, i);
		description  = IOPSGetPowerSourceDescription(power_sources_info, power_source);

    // skip power sources that are not present (i.e. an absent second battery in a 2-battery machine)
    if ((CFBooleanRef)CFDictionaryGetValue(description, CFSTR(kIOPSIsPresentKey)) == kCFBooleanFalse)
      continue;

    if (stringsAreEqual((CFStringRef)CFDictionaryGetValue(description, CFSTR (kIOPSTransportTypeKey)), CFSTR (kIOPSInternalType))) 
    {
      CFStringRef currentState = (CFStringRef)CFDictionaryGetValue(description, CFSTR (kIOPSPowerSourceStateKey));

      if (stringsAreEqual (currentState, CFSTR (kIOPSACPowerValue)))
      {
        ctx->m_OnBattery = false;
        ctx->m_BatteryPercent = 100;
        ctx->m_SentBatteryMessage = false;
      }
      else if (stringsAreEqual (currentState, CFSTR (kIOPSBatteryPowerValue)))
      {
        CFNumberRef cf_number_ref;
        int32_t curCapacity, maxCapacity;

        cf_number_ref = (CFNumberRef)CFDictionaryGetValue(description, CFSTR(kIOPSCurrentCapacityKey));
        CFNumberGetValue(cf_number_ref, kCFNumberSInt32Type, &curCapacity);

        cf_number_ref = (CFNumberRef)CFDictionaryGetValue(description, CFSTR(kIOPSMaxCapacityKey));
        CFNumberGetValue(cf_number_ref, kCFNumberSInt32Type, &maxCapacity);

        ctx->m_OnBattery = true;
        ctx->m_BatteryPercent = (int)((double)curCapacity/(double)maxCapacity * 100);
      }
		} 
  }

  CFRelease(power_sources_list);
  CFRelease(power_sources_info);
#endif
}
Ejemplo n.º 3
0
cgicc::CgiEnvironment::CgiEnvironment(CgiInput *input)
{
  // Create a local CgiInput object for us to use
  // In the vast majority of cases, this will be used
  // For FastCGI applications it won't but the performance hit of
  // an empty inline constructor is negligible
  CgiInput local_input;

  if(0 == input)
    readEnvironmentVariables(&local_input);
  else
    readEnvironmentVariables(input);

  // On Win32, use binary read to avoid CRLF conversion
#ifdef WIN32
#  ifdef __BORLANDC__
  setmode(_fileno(stdin), O_BINARY);
#  else
  _setmode(_fileno(stdin), _O_BINARY);
#  endif
#endif
     
  if(stringsAreEqual(fRequestMethod, "post") || stringsAreEqual(fRequestMethod, "put")) {
    // Don't use auto_ptr, but vector instead
    // Bug reported by [email protected]
    std::vector<char> data(fContentLength);
    
    if(getenv("CGICC_MAX_CONTENTLENGTH")&&getContentLength()>(long unsigned int)atoi(getenv("CGICC_MAX_CONTENTLENGTH")))
    {
      exit(1);
    }
    else
    // If input is 0, use the default implementation of CgiInput
	if ( getContentLength() )
	{
	// If input is 0, use the default implementation of CgiInput
		if ( input == 0 )
		{
		if ( local_input.read( &data[0], getContentLength() ) != getContentLength() )
		throw std::runtime_error("I/O error");
		}
		else
		if ( input->read( &data[0], getContentLength() ) != getContentLength() )
		throw std::runtime_error("I/O error");

		fPostData = std::string( &data[0], getContentLength() );
	} 
  }
  
  fCookies.reserve(10);
  parseCookies();
}
Ejemplo n.º 4
0
void
cgicc::CgiEnvironment::restore(const std::string& filename)
{
  std::ifstream file( filename.c_str(), std::ios::binary | std::ios::in );

  if( ! file )
    throw std::runtime_error("I/O error");

  file.flags(file.flags() & std::ios::skipws);

  fContentLength 	= readLong(file);
  fServerPort 		= readLong(file);
  fUsingHTTPS 		= (bool) readLong(file);

  fServerSoftware 	= readString(file);
  fServerName 		= readString(file);
  fGatewayInterface 	= readString(file);
  fServerProtocol 	= readString(file);
  fRequestMethod 	= readString(file);
  fPathInfo 		= readString(file);
  fPathTranslated 	= readString(file);
  fScriptName 		= readString(file);
  fQueryString 		= readString(file);
  fRemoteHost 		= readString(file);
  fRemoteAddr 		= readString(file);
  fAuthType 		= readString(file);
  fRemoteUser 		= readString(file);
  fRemoteIdent 		= readString(file);
  fContentType 		= readString(file);
  fAccept 		= readString(file);
  fUserAgent 		= readString(file);
  fRedirectRequest 	= readString(file);
  fRedirectURL 		= readString(file);
  fRedirectStatus	= readString(file);
  fReferrer 		= readString(file);
  fCookie 		= readString(file);
  
  if(stringsAreEqual(fRequestMethod, "post") || stringsAreEqual(fRequestMethod, "put"))
    fPostData = readString(file);

  file.close();

  fCookies.clear();
  fCookies.reserve(10);
  parseCookies();
}
Ejemplo n.º 5
0
void
cgicc::CgiEnvironment::save(const std::string& filename) 	const
{
  std::ofstream file( filename.c_str(), std::ios::binary |std::ios::out );

  if( ! file )
    throw std::runtime_error("I/O error");

  writeLong(file, fContentLength);
  writeLong(file, fServerPort);
  writeLong(file, (unsigned long) usingHTTPS());

  writeString(file, fServerSoftware);
  writeString(file, fServerName);
  writeString(file, fGatewayInterface);
  writeString(file, fServerProtocol);
  writeString(file, fRequestMethod);
  writeString(file, fPathInfo);
  writeString(file, fPathTranslated);
  writeString(file, fScriptName);
  writeString(file, fQueryString);
  writeString(file, fRemoteHost);
  writeString(file, fRemoteAddr);
  writeString(file, fAuthType);
  writeString(file, fRemoteUser);
  writeString(file, fRemoteIdent);
  writeString(file, fContentType);
  writeString(file, fAccept);
  writeString(file, fUserAgent);
  writeString(file, fRedirectRequest);
  writeString(file, fRedirectURL);
  writeString(file, fRedirectStatus);
  writeString(file, fReferrer);
  writeString(file, fCookie);
  
  if(stringsAreEqual(fRequestMethod, "post") || stringsAreEqual(fRequestMethod, "put"))
    writeString(file, fPostData);

  if(file.bad() || file.fail())
    throw std::runtime_error("I/O error");

  file.close();
}
Ejemplo n.º 6
0
// Read in all the environment variables
void
cgicc::CgiEnvironment::readEnvironmentVariables(CgiInput *input)
{
    fServerSoftware 	= input->getenv("SERVER_SOFTWARE");
    fServerName 		= input->getenv("SERVER_NAME");
    fGatewayInterface 	= input->getenv("GATEWAY_INTERFACE");
    fServerProtocol 	= input->getenv("SERVER_PROTOCOL");

    std::string port 	= input->getenv("SERVER_PORT");
    fServerPort 		= std::atol(port.c_str());

    fRequestMethod 	= input->getenv("REQUEST_METHOD");
    fPathInfo 		= input->getenv("PATH_INFO");
    fPathTranslated 	= input->getenv("PATH_TRANSLATED");
    fScriptName 		= input->getenv("SCRIPT_NAME");
    fQueryString 		= input->getenv("QUERY_STRING");
    fRemoteHost 		= input->getenv("REMOTE_HOST");
    fRemoteAddr 		= input->getenv("REMOTE_ADDR");
    fAuthType 		= input->getenv("AUTH_TYPE");
    fRemoteUser 		= input->getenv("REMOTE_USER");
    fRemoteIdent 		= input->getenv("REMOTE_IDENT");
    fContentType 		= input->getenv("CONTENT_TYPE");

    std::string length 	= input->getenv("CONTENT_LENGTH");
    fContentLength 	= std::atol(length.c_str());

    fAccept 		= input->getenv("HTTP_ACCEPT");
    fUserAgent 		= input->getenv("HTTP_USER_AGENT");
    fRedirectRequest 	= input->getenv("REDIRECT_REQUEST");
    fRedirectURL 		= input->getenv("REDIRECT_URL");
    fRedirectStatus 	= input->getenv("REDIRECT_STATUS");
    fReferrer 		= input->getenv("HTTP_REFERER");
    fCookie 		= input->getenv("HTTP_COOKIE");
    fAcceptLanguageString = input->getenv("HTTP_ACCEPT_LANGUAGE");

    // Win32 bug fix by Peter Goedtkindt
    std::string https 	= input->getenv("HTTPS");
    if(stringsAreEqual(https, "on"))
        fUsingHTTPS = true;
    else
        fUsingHTTPS = false;


}
Ejemplo n.º 7
0
static void powerSourceChanged(void *context)
{
#pragma unused(context)
	CFTypeRef	powerBlob = IOPSCopyPowerSourcesInfo();
	CFArrayRef	powerSourcesList = IOPSCopyPowerSourcesList(powerBlob);

	CFIndex	count = CFArrayGetCount(powerSourcesList);
	for (CFIndex i = 0; i < count; ++i) {
		CFTypeRef		powerSource;
		CFDictionaryRef description;

		HGPowerSource	hgPowerSource;
		CFBooleanRef	charging = kCFBooleanFalse;
		CFIndex			batteryTime = -1;
		CFIndex			percentageCapacity = -1;

		powerSource = CFArrayGetValueAtIndex(powerSourcesList, i);
		description = IOPSGetPowerSourceDescription(powerBlob, powerSource);

		//Don't display anything for power sources that aren't present (i.e. an absent second battery in a 2-battery machine)
		if (CFDictionaryGetValue(description, CFSTR(kIOPSIsPresentKey)) == kCFBooleanFalse)
			continue;

		//We only know how to handle internal (battery, a/c power) transport types. The other values indicate UPS usage.
		if (stringsAreEqual(CFDictionaryGetValue(description, CFSTR(kIOPSTransportTypeKey)),
							CFSTR(kIOPSInternalType))) {
			CFStringRef currentState = CFDictionaryGetValue(description, CFSTR(kIOPSPowerSourceStateKey));
			if (stringsAreEqual(currentState, CFSTR(kIOPSACPowerValue)))
				hgPowerSource = HGACPower;
			else if (stringsAreEqual(currentState, CFSTR(kIOPSBatteryPowerValue)))
				hgPowerSource = HGBatteryPower;
			else
				hgPowerSource = HGUnknownPower;

			//Battery power
			if (CFDictionaryGetValue(description, CFSTR(kIOPSIsChargingKey)) == kCFBooleanTrue) {
				//Charging
				charging = kCFBooleanTrue;

				CFNumberRef timeToChargeNum = CFDictionaryGetValue(description, CFSTR(kIOPSTimeToFullChargeKey));
				CFIndex timeToCharge;

				if (CFNumberGetValue(timeToChargeNum, kCFNumberCFIndexType, &timeToCharge))
					batteryTime = timeToCharge;
			} else {
				//Not charging
				charging = kCFBooleanFalse;

				CFNumberRef timeToEmptyNum = CFDictionaryGetValue(description, CFSTR(kIOPSTimeToEmptyKey));
				CFIndex timeToEmpty;

				if (CFNumberGetValue(timeToEmptyNum, kCFNumberCFIndexType, &timeToEmpty))
					batteryTime = timeToEmpty;
			}

			/* Capacity */
			CFNumberRef currentCapacityNum = CFDictionaryGetValue(description, CFSTR(kIOPSCurrentCapacityKey));
			CFNumberRef maxCapacityNum = CFDictionaryGetValue(description, CFSTR(kIOPSMaxCapacityKey));

			CFIndex currentCapacity, maxCapacity;

			if (CFNumberGetValue(currentCapacityNum, kCFNumberCFIndexType, &currentCapacity) &&
					CFNumberGetValue(maxCapacityNum, kCFNumberCFIndexType, &maxCapacity))
				percentageCapacity = roundf((currentCapacity / (float)maxCapacity) * 100.0f);

		} else {
			//UPS power
			hgPowerSource = HGUPSPower;
		}

		//Avoid sending notifications on the same power source multiple times, unless the charging state or presence/absence of a time estimate has changed.
		if (lastPowerSource != hgPowerSource || lastChargingState != charging || (lastBatteryTime == -1) != (batteryTime == -1)) {
			lastPowerSource = hgPowerSource;
			lastChargingState = charging;
			lastBatteryTime = batteryTime;
			AppController_powerSwitched(hgPowerSource, charging, batteryTime, percentageCapacity);
		}
	}

	CFRelease(powerSourcesList);
	CFRelease(powerBlob);
}
Ejemplo n.º 8
0
 inline bool operator() (const FormFile& entry) 	const
 { return stringsAreEqual(fName, entry.getName()); }
Ejemplo n.º 9
0
 inline bool operator() (const FormEntry& entry) 	const
 { return stringsAreEqual(fValue, entry.getValue()); }
Ejemplo n.º 10
0
void
cgicc::Cgicc::parseFormInput(const std::string& data, const std::string &content_type)
{
  
  std::string standard_type	= "application/x-www-form-urlencoded";
  std::string multipart_type 	= "multipart/form-data";

  // Don't waste time on empty input
  if(true == data.empty())
    return;

  // Standard content type = application/x-www-form-urlencoded
  // It may not be explicitly specified
  if(true == content_type.empty() 
     || stringsAreEqual(content_type, standard_type,standard_type.length())) {
    std::string name, value;
    std::string::size_type pos;
    std::string::size_type oldPos = 0;

    // Parse the data in one fell swoop for efficiency
    while(true) {
      // Find the '=' separating the name from its value, also have to check for '&' as its a common misplaced delimiter but is a delimiter none the less
      pos = data.find_first_of( "&=", oldPos);
      
      // If no '=', we're finished
      if(std::string::npos == pos)
	break;
      
      // Decode the name
	// pos == '&', that means whatever is in name is the only name/value
      if( data.at( pos ) == '&' )
	  {
	  	const char * pszData = data.c_str() + oldPos;
		while( *pszData == '&' ) // eat up extraneous '&'
		{
			++pszData; ++oldPos;
		}
		if( oldPos >= pos )
		{ // its all &'s
			oldPos = ++pos;
			continue;
		}
		// this becomes an name with an empty value
		name = form_urldecode(data.substr(oldPos, pos - oldPos));
		fFormData.push_back(FormEntry(name, "" ) );
		oldPos = ++pos;
		continue;
	  }
      name = form_urldecode(data.substr(oldPos, pos - oldPos));
      oldPos = ++pos;
      
      // Find the '&' or ';' separating subsequent name/value pairs
      pos = data.find_first_of(";&", oldPos);
      
      // Even if an '&' wasn't found the rest of the string is a value
      value = form_urldecode(data.substr(oldPos, pos - oldPos));

      // Store the pair
      fFormData.push_back(FormEntry(name, value));
      
      if(std::string::npos == pos)
	break;

      // Update parse position
      oldPos = ++pos;
    }
  }
  // File upload type = multipart/form-data
  else if(stringsAreEqual(multipart_type, content_type,
			  multipart_type.length())){

    // Find out what the separator is
    std::string 		bType 	= "boundary=";
    std::string::size_type 	pos 	= content_type.find(bType);

    // Remove next sentence
    std::string                 commatek=";";

    // generate the separators
    std::string sep1 = content_type.substr(pos + bType.length());
    if (sep1.find(";")!=std::string::npos)
       sep1=sep1.substr(0,sep1.find(";"));
    sep1.append("\r\n");
    sep1.insert(0, "--");

    std::string sep2 = content_type.substr(pos + bType.length());
    if (sep2.find(";")!=std::string::npos)
       sep2=sep2.substr(0,sep2.find(";"));
    sep2.append("--\r\n");
    sep2.insert(0, "--");

    // Find the data between the separators
    std::string::size_type start  = data.find(sep1);
    std::string::size_type sepLen = sep1.length();
    std::string::size_type oldPos = start + sepLen;

    while(true) {
      pos = data.find(sep1, oldPos);

      // If sep1 wasn't found, the rest of the data is an item
      if(std::string::npos == pos)
	break;

      // parse the data
      parseMIME(data.substr(oldPos, pos - oldPos));

      // update position
      oldPos = pos + sepLen;
    }

    // The data is terminated by sep2
    pos = data.find(sep2, oldPos);
    // parse the data, if found
    if(std::string::npos != pos) {
      parseMIME(data.substr(oldPos, pos - oldPos));
    }
  }
}
Ejemplo n.º 11
0
bool 
cgicc::Cgicc::queryCheckbox(const std::string& elementName) 	const
{
  const_form_iterator iter = getElement(elementName);
  return (iter != fFormData.end() && stringsAreEqual(iter->getValue(), "on"));
}