char* FUNC_FLASHMEM inplaceURLDecode(char* str)
	{
		char* rpos = str;
		char* wpos = str;
		while (*rpos)
		{
			if (*rpos == '%')
			{
				if (isxdigit(rpos[1]) && rpos[2] && isxdigit(rpos[2]))
				{
					*wpos++ = (hexDigitToInt(rpos[1]) << 4) | hexDigitToInt(rpos[2]);
					rpos += 3;
				}
			}
			else if (*rpos == '+')
			{
				*wpos++ = 0x20;
				++rpos;
			}
			else
			{
				*wpos++ = *rpos++;
			}
		}
		*wpos = 0;
		return str;
	}
Beispiel #2
0
CckBool
transportAddressFromString_ethernet (CckTransportAddress *out, const char *address)
{

    int i;
    int digit;
    int octet;
    unsigned char *addr = (unsigned char*) address;

    clearTransportAddress(out);
    out->family = TT_FAMILY_ETHERNET;

    if(!ether_hostton(address, &out->addr.ether)) {
	return CCK_TRUE;
    }

    if(strlen(address) > TT_STRADDRLEN_ETHERNET) {
	CCK_ERROR("transportAddressFromString: Ethernet address too long: %s\n", address);
	return CCK_FALSE;
    }

    /* ...because ether_aton_r... */
    for(i = 0; i < 6; i++) {

	if((digit = hexDigitToInt(*addr++)) < 0) {
	    break;
	}

	if(!*addr || (*addr == ':')) {
	    octet = digit;
	    out->addr.ether.ether_addr_octet[i] = octet;
	} else {
	    octet = digit << 4;
	    if((digit = hexDigitToInt(*addr++)) < 0) {
		break;
	    }
	    octet += digit;
	    out->addr.ether.ether_addr_octet[i] = octet;
	}

	if(*addr == ':') {
	    addr++;
	}

    }

    if(i == 6 ) return CCK_TRUE;

    CCK_ERROR("Could not resolve / encode Ethernet address: %s\n",
		address);

    return CCK_FALSE;

}
//! \exception StSRecordParseException is thrown if either of the nibble characters
//!		is not a valid hex digit.
int StSRecordFile::readHexByte(std::string &inString, int inIndex)
{
    char nibbleCharHi = inString[inIndex];
    char nibbleCharLo = inString[inIndex + 1];

    // must be hex digits
    if (!(isHexDigit(nibbleCharHi) && isHexDigit(nibbleCharLo)))
    {
        throw StSRecordParseException("invalid hex digit");
    }

    return (hexDigitToInt(nibbleCharHi) << 4) | hexDigitToInt(nibbleCharLo);
}
Beispiel #4
0
bool MessageState::stringHex(Common::String &outStr, const Common::String &inStr, uint &index) {
	// Hex escape sequences of the form \nn, where n is a hex digit
	if (inStr[index] != '\\')
		return false;

	// Check for enough room for a hex escape sequence
	if (index + 2 >= inStr.size())
		return false;

	int digit1 = hexDigitToInt(inStr[index + 1]);
	int digit2 = hexDigitToInt(inStr[index + 2]);

	// Check for hex
	if ((digit1 == -1) || (digit2 == -1))
		return false;

	outStr += digit1 * 16 + digit2;
	index += 3;

	return true;
}