void PusherClient::getAuthString(const String& channel, String& auth)
{
	Sha256Class sha256;
	
	//Sha init with secret key
	{
		String secret;
		getPusherInfoItem(2, secret);
		sha256.initHmac((uint8_t*)&secret[0], secret.length());
	}
	
	//Set the data to encrypt
	{
		String text;
		text.reserve(_socketid.length() + 1 + channel.length());
		text = _socketid;
		text += ':';
		text += channel;
		sha256.print(text);
	}
	
	uint8_t* result = sha256.resultHmac();
	
	String hexChars;
	getStringTableItem(19, hexChars);
	
	auth.reserve(21 /*key*/ + 1 + 64 /*sha256*/);	
	getPusherInfoItem(1, auth); //key
	auth += ':';	
	for (int i=0; i<32; i++)
	{
		auth += hexChars.charAt(result[i]>>4);
		auth += hexChars.charAt(result[i]&0xf);
	}
}
void ESP8266WebServerEx::redirect(const char* homePath) {
  uint16_t port = g_ModuleSettings.data.port;
  String url;

  if ( !homePath ) return;
  url.reserve(50);
  url = "http://";
  url += GetHost();
  url += homePath;
  
  String content;
  content.reserve(250);

  content = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta http-equiv=\"refresh\" content=\"0; URL='";
  content += url;
  content += "'\" />\n<title>Login</title>\n</head>\n<body onload=\"window.location='";
  content += url;
  content += "';\">\n</body>\n</html>";

  sendHeader("Location",url);
  sendHeader("Cache-Control","no-cache");
  sendHeader("Pragma","no-cache");

  TRACE("Redirect...");
    
  send(302,"text/html",content);
}
Example #3
0
    String JID::generateDescription(String localPart, String domainPart, String resourcePart)
    {
        String description;
        if (!resourcePart.empty()) {
            if (!localPart.empty()) {
                description.reserve(localPart.length() + domainPart.length() + resourcePart.length() + 2);
                description += localPart;
                description += "@";
                description += domainPart;
                description += "/";
                description += resourcePart;
            } else {
                description.reserve(domainPart.length() + resourcePart.length() + 1);
                description += domainPart;
                description += "/";
                description += resourcePart;
            }
        } else {
            if (!localPart.empty()) {
                description.reserve(localPart.length() + domainPart.length() + 1);
                description += localPart;
                description += "@";
                description += domainPart;
            } else {
                description = domainPart;
            }
        }

        return description;
    }
void setup()
{
	response.reserve(RESPONSE_BUFFER);
	url.reserve(STRING_BUFFER);
	cmd.reserve(COMMAND_BUFFER);

	Serial.begin(9600);
	Serial.println("PowerInterlock Start");
	turnOff();
	disableTiming();

	RFID.begin(2400);
	delay(500);

	pinMode(RFID_ENABLE, OUTPUT);
	//digitalWrite(RFID_ENABLE, LOW);
	pinMode(DEVICE_PIN, OUTPUT);

	Ethernet.begin(mac, ip, dns1);
	//After a couple hours, the DHCP started to fail for some reason
	/*if (Ethernet.begin(mac) == 0) {
		Serial.println("Failed to configure Ethernet using DHCP");
		Ethernet.begin(mac, ip);
	}*/
	// give the Ethernet shield a second to initialize:
	delay(1000);
}
Example #5
0
void BootConfig::_onDeviceInfoRequest() {
  Logger.logln("Received device info request");

  DynamicJsonBuffer jsonBuffer;
  JsonObject& json = jsonBuffer.createObject();
  json["device_id"] = Helpers.getDeviceId();
  json["homie_version"] = VERSION;
  JsonObject& firmware = json.createNestedObject("firmware");
  firmware["name"] = this->_shared_interface->fwname;
  firmware["version"] = this->_shared_interface->fwversion;

  JsonArray& nodes = json.createNestedArray("nodes");
  for (int i = 0; i < this->_shared_interface->nodes.size(); i++) {
    HomieNode node = this->_shared_interface->nodes[i];
    JsonObject& json_node = jsonBuffer.createObject();
    json_node["id"] = node.id;
    json_node["type"] = node.type;

    nodes.add(json_node);
  }

  // 110 bytes for {"homie_version":"11.10.0","firmware":{"name":"awesome-light-great-top","version":"11.10.0-beta"},"nodes":[]}
  // 60 bytes for {"id":"lightifydefoulooooo","type":"lightifydefouloooo"}, (-1 for leading ","), +1 for terminator
  String jsonString;
  jsonString.reserve(110 + (60 * this->_shared_interface->nodes.size()) - 1 + 1);
  json.printTo(jsonString);
  this->_http.send(200, FPSTR(PROGMEM_CONFIG_APPLICATION_JSON), jsonString);
}
Example #6
0
  String::size_type ccppFile::readFile( String & str )
  {
    str.reserve(getSize());

    char buff[1024];

    std::fstream & fStr= getStream();
    //String::size_type size = 0;

    while ( ! fStr.eof() )
    {
      fStr.read( buff, sizeof(buff) );

      if ( fStr.bad() )
      {
				throw std::runtime_error("Error while reading from file stream (bad)");
      }
      else if ( fStr.fail() )
      {
        if (! fStr.eof() )
        {
					throw std::runtime_error("Error while reading from file stream (fail)");
        }
      }
      str.append( buff,fStr.gcount() );
      //size+= fStr.gcount();
    }

    return str.length();
  }
Example #7
0
String format_strings(const String& fmt, const String *args[], size_t nargs)
{
	String str;
	str.reserve(fmt.length() * 2);
	String::const_iterator it;
	for (it = fmt.begin(); it != fmt.end(); ++it)
	{
		if (*it == '%')
		{
			++it;
			if (it == fmt.end())
				break;
			int n = *it - '0';
			if (n > 0 && static_cast<unsigned int>(n) <= nargs)
				str += *args[n - 1];
			else
				str += *it;
		}
		else
		{
			str += *it;
		}
	}
	return str;
}
Example #8
0
void setup()
{
    
    randomSeed((analogRead(A4) & 0x1F) | (analogRead(A5) << 5));
    pinMode(ledPin, OUTPUT);
    digitalWrite(ledPin, LOW); //start LED off
    pinMode(PPM_pin, INPUT);
    pinMode(MOSI_pin, OUTPUT);
    pinMode(SCK_pin, OUTPUT);
    pinMode(CS_pin, OUTPUT);
    pinMode(CE_pin, OUTPUT);
    pinMode(MISO_pin, INPUT);

    // PPM ISR setup
    //attachInterrupt(PPM_pin - 2, ISR_ppm, CHANGE);
    TCCR1A = 0;  //reset timer1
    TCCR1B = 0;
    TCCR1B |= (1 << CS11);  //set timer1 to increment every 1 us @ 8MHz, 0.5 us @16MHz

    set_txid(false);

    // Serial port input/output setup
    Serial.begin(115200);
    // reserve 200 bytes for the inputString:
    inputString.reserve(200);
}
Example #9
0
String strutil_flatten_array(const wxArrayString& array, wxChar chSep)
{
   String s;
   s.reserve(1024);

   const size_t count = array.GetCount();
   for ( size_t n = 0; n < count; n++ )
   {
      if ( n > 0 )
         s += chSep;

      for ( String::const_iterator p = array[n].begin(),
                                 end = array[n].end();
            p != end;
            ++p )
      {
         const wxChar ch = *p;

         // escape the separator characters
         if ( ch == chSep || ch == '\\' )
            s += '\\';

         s += ch;
      }
   }

   return s;
}
void AVL_tree::SendNodes(Node node, EthernetClient* client){
  if(node){
    SendNodes(node->left, client);
    // DO STRING
    String* buffer = new String("");
    buffer->reserve(sizeof(unsigned char)*20);
    *buffer += node->d;
    *buffer += ':';
    if(node->status)
      *buffer += '1';
    else
      *buffer += '0';
    *buffer += ':';
    *buffer += node->timerid;
    *buffer += ':' ;
    *buffer +=  node->onHour;
    *buffer += ':' ;
    *buffer += node->onMinute;
    *buffer += ':' ;
    *buffer += node->offHour;
    *buffer += ':';
    *buffer +=  node->offMinute;
    *buffer += 'N';
    client->print(*buffer);
    Serial.println(*buffer);
    delete buffer;
    SendNodes(node->right, client);
  }
}
Example #11
0
/** Enforces LF '\n' newline convention.

    @param in string to copy
    @return the UNIXified string
*/
String
strutil_enforceLF(String const &in)
{
   String out;
   out.reserve(in.length());

   size_t cursor = 0;
   
   while ( cursor < in.size() )
   {
      wxChar one = in[cursor];
      if ( one != _T('\r') )
      {
         out += one;
         cursor++;
      }
      else
      {
         out += '\n';
         if ( cursor + 1 < in.size() )
         {
            if ( in[cursor + 1] == '\n' )
               cursor += 2;
            else
               cursor++;
         }
         else
            cursor++;
      }
   }
   
   return out;
}
void Document::loadFileToString( const String& file_name_, String &buffer_ )
{
	FRL_EXCEPT_GUARD();
	if( ! fs::exists( file_name_ ) )
		FRL_THROW_S_CLASS( Document::FileNotFound );
	size_t length = static_cast< size_t >( fs::file_size( file_name_ ) );
	if( length == 0 )
		FRL_THROW_S_CLASS( Document::EmptyFile );
	if( ! buffer_.empty() )
		buffer_.clear();

	static const size_t buffer_size = 4096;
	stream_std::InFile in( file_name_.c_str(), std::ios::binary );
	if( ! in.is_open() )
		FRL_THROW_S_CLASS( Document::UnknownError );
	std::vector< Char > buf( buffer_size );

	buffer_.reserve( length );
	while( in )
	{
		in.read( &buf[ 0 ], buffer_size );
		buffer_.append( &buf[ 0 ], in.gcount() );
	}
	in.close();
}
Example #13
0
void DesktopFile::set_not_show_in(const list<String>& lst) {
	/* 
	 * Desktop entry specs requires only one of OnlyShowIn or NotShowIn
	 * can exists in one section 
	 */
	if(Config::key_exist(ENTRY_SECT, "OnlyShowIn"))
		return;

	if(lst.empty())
		return;

	if(errcode != DESK_FILE_SUCCESS && errcode != DESK_FILE_EMPTY)
		return;

	String all;
	all.reserve(256);
	list<String>::const_iterator it = lst.begin(), it_end = lst.end();

	for(; it != it_end; ++it) {
		all += (*it);
		all += ';'; // intentionally since value must ends with ':'
	}

	Config::set(ENTRY_SECT, "NotShowIn", all.c_str());
}
Example #14
0
/** Enforces CR/LF newline convention.

    @param in string to copy
    @return the DOSified string
*/
String
strutil_enforceCRLF(String const &in)
{
   String out;
   out.reserve(in.length());

   const wxChar *cptr = in.c_str();
   bool has_cr =  false;

   if(! cptr)
      return wxEmptyString;
   while(*cptr)
   {
      switch(*cptr)
      {
      case '\r':
         has_cr = true;
         out += '\r';
         break;
      case '\n':
         if(! has_cr)
            out += '\r';
         out += '\n';
         has_cr = false;
         break;
      default:
         out += *cptr;
         has_cr = false;
         break;
      }
      cptr++;
   }
   return out;
}
String XMLSerializer::convertEntityInText(const String& text)
{
    String res;
    res.reserve(text.size()*2);
    const String::const_iterator iterEnd = text.end();
    for (String::const_iterator iter = text.begin(); iter != iterEnd ; ++iter)
    {
        switch(*iter)
        {  
            case '<':
                res += "&lt;";
                break;
      
            case '>':
                res += "&gt;";
                break;
        
            case '&':
                res += "&amp;";
                break;
        
            case '\'':
                res += "&apos;";
                break;

            case '"':
                res += "&quot;";
                break;
      
            default:
                res += *iter;
        }
    }
    return res;
}
	//-----------------------------------------------------------------------
	String ConfigFileEx::deconvertSpecialChars(const String& _str)
	{
		String ret;
		ret.reserve(_str.length());
		size_t i = 0; 
		while(i != _str.length())
		{
			char ch = _str[i++];
			if(ch == '\\')
			{
				ch = _str[i++];
				switch(ch)
				{
					case 'n': ret += '\n'; break;
					case 'r': ret += '\r'; break;
					case 't': ret += '\t'; break;
					default:  ret += ch;
				}
			}
			else
			{
				ret += ch;
			}
		}
		return ret;
	}
Example #17
0
File: Rct.cpp Project: farva/rct
String colorize(const String &string, AnsiColor color, int from, int len)
{
    assert(from <= string.size());
    assert(from >= 0);
    if (len == -1) {
        len = string.size() - from;
    }
    assert(from + len <= string.size());
    if (!len)
        return string;

    String ret;
    ret.reserve(string.size() + 20);
    const char *str = string.constData();
    if (from > 0) {
        ret.append(str, from);
        str += from;
    }
    ret.append(colors[color]);
    ret.append(str, len);
    str += len;
    ret.append(colors[AnsiColor_Default]);
    if (from + len != string.size())
        ret.append(str, string.size() - from - len);

    return ret;
}
Example #18
0
String xxtea_c::encrypt(String data)
{
  // Works only if the Key in setup
  if(this->keyset && data.length() != 0)
  {
    // If the Data within the limits of the Engine
    if(data.length() < MAX_XXTEA_DATA8)
    {
      size_t len;
      // Assign the Maximum buffer we have
      len = MAX_XXTEA_DATA8;
      // Perform Encryption
      if(xxtea_encrypt((uint8_t *)data.c_str(),data.length(),
        this->data,&len) == XXTEA_STATUS_SUCCESS)
      {
        String result;
        size_t i;
        result.reserve(len*2 + 1);
        result = "";
        for(i=0;i<len;i++)
        {
          result+=tohex((this->data[i] >> 4) & 0x0F);
          result+=tohex(this->data[i] & 0x0F);
        }
        return result;
      }
    }
Example #19
0
    //---------------------------------
    String Utils::checkNCName ( const String &ncName )
    {
        String result;
        result.reserve ( ncName.length() );

        // check if first character is an alpha character
        char firstCharacter = ncName[0];

        if ( isAsciiAlphaChar ( firstCharacter )  )
            result.append ( 1, firstCharacter );
        else
            result.append ( 1, '_' );

        //replace all spaces and colons by underlines
        for ( size_t i = 1; i<ncName.length(); ++i )
        {
            char character = ncName[i];

            if ( isIDChar ( character ) )
                result.append ( 1, character );
            else
                result.append ( 1, '_' );
        }

        return result;
    }
void ArduRPC_SensorNode::submitData()
{
  uint16_t i;
  char hostname[NODE_EEPROM_API_HOSTNAME_MAX_LENGTH + 1];
  uint16_t port;

  if(this->status != 4) {
    return;
  }

  if(WiFi.status() != WL_CONNECTED) {
    return;
  }

/*
  if(connectSensorAPI() == false) {
    return;
  }
*/
  getAPIHostnameOrDefault(&hostname[0], NODE_EEPROM_API_HOSTNAME_MAX_LENGTH);
  port = getAPIPortOrDefault();

  HTTPClient http;

  String path;
  path.reserve(64);
  path = "/sensors/";
  path += this->sensor_uuid;

  http.begin(hostname, port, path);
  http.addHeader("X-Sensor-Api-Key", this->sensor_key);
  http.addHeader("X-Sensor-Version", "1");
  int code;
  code = http.POST(this->cache.data, this->cache.length);
  NODE_DEBUG_PRINT("Code ");
  NODE_DEBUG_PRINTLN(code);

  // ToDo: validate code
  this->status = 0;

/*
  client.print("POST /sensors/");
  client.println(this->sensor_uuid);
  client.print("Host: ");
  client.println(hostname);
  client.println("Connection: close");
  client.print("X-Sensor-Api-Key: ");
  client.println(this->sensor_key);
  client.println("X-Sensor-Version: 1");
  client.print("Content-Length: ");
  client.println(this->cache.length);
  client.println();
  for(i = 0; i < this->cache.length; i++) {
    Serial.print((char)this->cache.data[i]);
  }
  this->status = 0;
  client.stop();
*/
}
Example #21
0
String ToString<std::string> (std::string str)
{
	String ret;
	ret.reserve (str.size());
	for (auto c : str)
		ret += Char(c);
	return ret;
}
Example #22
0
const String operator+(const String& str, const StringRef& strRef)
{
    String ret;
    ret.reserve(str.length() + strRef.length());
    ret.append(str);
    ret.append(strRef);
    return ret;
}
Example #23
0
const String operator+(const String& str1, const String& str2)
{
    String ret;
    ret.reserve(str1.length() + str2.length());
    ret.append(str1);
    ret.append(str2);
    return ret;
}
Example #24
0
const String operator+(const String& str, char c)
{
    String ret;
    ret.reserve(str.length() + 1);
    ret.append(str);
    ret.appendChar(c);
    return ret;
}
Example #25
0
  String Publish::payload_string(void) const {
    String str;
    str.reserve(_payload_len);
    for (uint32_t i = 0; i < _payload_len; i++)
      str += (char)_payload[i];

    return str;
  }
Example #26
0
		void Reserve(String &Str,size_t Size)
		{
			if (Size>size_t(Str.max_size()))
				return;

			if (Str.capacity()<Size)
				Str.reserve(Size);
		}
Example #27
0
CXChildVisitResult DumpThread::visitor(CXCursor cursor, CXCursor, CXClientData userData)
{
    DumpThread *that = reinterpret_cast<DumpThread*>(userData);
    assert(that);
    CXSourceLocation location = clang_getCursorLocation(cursor);
    if (!clang_equalLocations(location, nullLocation)) {
        CXString file;
        unsigned line, col;
        clang_getPresumedLocation(location, &file, &line, &col);
        Path path = RTags::eatString(file);
        if (!path.isEmpty()) {
            uint32_t &fileId = that->mFiles[path];
            if (!fileId) {
                const Path resolved = path.resolved();
                fileId = Location::insertFile(resolved);
                that->mFiles[path] = that->mFiles[resolved] = fileId;
            }
            if (that->mQueryFlags & QueryMessage::DumpIncludeHeaders || fileId == that->mSource.fileId) {
                const Location loc(fileId, line, col);
                String message;
                message.reserve(256);
                if (!(that->mQueryFlags & QueryMessage::NoContext))
                    message += loc.context();

                CXSourceRange range = clang_getCursorExtent(cursor);
                CXSourceLocation rangeEnd = clang_getRangeEnd(range);
                unsigned endLine, endColumn;
                clang_getPresumedLocation(rangeEnd, 0, &endLine, &endColumn);
                if (endLine == line) {
                    message += String::format<32>(" // %d-%d, %d: ", col, endColumn, that->mIndentLevel);
                } else {
                    message += String::format<32>(" // %d-%d:%d, %d: ", col, endLine, endColumn, that->mIndentLevel);
                }
                message += RTags::cursorToString(cursor, RTags::AllCursorToStringFlags);
                message.append(" " + RTags::typeName(cursor) + " ");
                CXCursor ref = clang_getCursorReferenced(cursor);
                if (clang_equalCursors(ref, cursor)) {
                    message.append("refs self");
                } else if (!clang_equalCursors(ref, nullCursor)) {
                    message.append("refs ");
                    message.append(RTags::cursorToString(ref, RTags::AllCursorToStringFlags));
                }

                CXCursor canonical = clang_getCanonicalCursor(cursor);
                if (!clang_equalCursors(canonical, cursor) && !clang_equalCursors(canonical, nullCursor)) {
                    message.append("canonical ");
                    message.append(RTags::cursorToString(canonical, RTags::AllCursorToStringFlags));
                }

                that->writeToConnetion(message);
            }
        }
    }
    ++that->mIndentLevel;
    clang_visitChildren(cursor, DumpThread::visitor, userData);
    --that->mIndentLevel;
    return CXChildVisit_Continue;
}
Example #28
0
  String read<String>(uint8_t *buf, uint32_t& pos) {
    uint16_t len = read<uint16_t>(buf, pos);
    String val;
    val.reserve(len);
    for (uint16_t i = 0; i < len; i++)
      val += (char)read<uint8_t>(buf, pos);

    return val;
  }
Example #29
0
  String read<String>(Client& client) {
    uint16_t len = read<uint16_t>(client);
    String val;
    val.reserve(len);
    for (uint16_t i = 0; i < len; i++)
      val += (char)read<uint8_t>(client);

    return val;
  }
Example #30
0
const String operator+(const String& str, const char* cstr)
{
    String ret;
    size_t cstrLen = ::strlen(cstr);
    ret.reserve(str.length() + cstrLen);
    ret.append(str);
    ret.append(cstr, cstrLen);
    return ret;
}