/* In-place percent decoding. */ static int percent_decode(char *s) { char *p, *q; /* Skip to the first '%'. If there are no percent escapes, this lets us return without doing any copying. */ q = s; while (*q != '\0' && *q != '%') q++; p = q; while (*q != '\0') { if (*q == '%') { int c, d; q++; c = hex_digit_value(*q); if (c == -1) return -1; q++; d = hex_digit_value(*q); if (d == -1) return -1; *p++ = c * 16 + d; q++; } else { *p++ = *q++; } } *p = '\0'; return p - s; }
// Decodes JavaScript-style (`encodeURIComponent()`) URL encoding (used for // translations) unsigned int url_decode( char const* encoded, char* decoded, size_t decoded_size ) { unsigned int i = 0; while(*encoded != 0 && i < decoded_size) { if(*encoded == '%') { if(*(encoded + 1) != 0 && *(encoded + 2) != 0) { decoded[i] = hex_digit_value(*(encoded + 1)) << 4 | hex_digit_value(*(encoded + 2)); encoded += 2; } } else if(encoded[0] == '+') { decoded[i] = ' '; } else { decoded[i] = *encoded; } encoded++; i++; } decoded[i] = 0; return i; }
void UpdateDataToDataStore(STETHERNET_MSG& ouEthernetMessage, string strData) { //Convert 2 characters to 1 byte "FF" to 0xFF for (int i = 0, j= 0; i < ouEthernetMessage.m_unDataLen ; i++, j+=2) { ouEthernetMessage.m_ucData[i] = (hex_digit_value(strData[j]) << 4) | ( hex_digit_value(strData[j+1])); } }
/* Parse a string of hex digits starting at HEX, supply them as the value of register REGNO, skip any whitespace, and return a pointer to the next character. There is a function in monitor.c, monitor_supply_register, which is supposed to do this job. However, there is some rather odd stuff in there (whitespace characters don't terminate numbers, for example) that is incorrect for ROM68k. It's basically impossible to safely tweak monitor_supply_register --- it's used by a zillion other monitors; who knows what behaviors they're depending on. So instead, we'll just use our own function, which can behave exactly the way we want it to. */ static char * rom68k_supply_one_register (int regno, unsigned char *hex) { ULONGEST value; unsigned char regbuf[MAX_REGISTER_SIZE]; value = 0; while (*hex != '\0') if (is_hex_digit (*hex)) value = (value * 16) + hex_digit_value (*hex++); else break; /* Skip any whitespace. */ while (is_whitespace (*hex)) hex++; store_unsigned_integer (regbuf, DEPRECATED_REGISTER_RAW_SIZE (regno), value); supply_register (regno, regbuf); return hex; }
int misc_init_r(void) { unsigned char serial[17], *old_serial; u8 addr[6]; old_serial = getenv("serial#"); if(NULL != old_serial) { system_serial[0] = hex_digit_value(old_serial[0]) * 16 + hex_digit_value(old_serial[1]); system_serial[1] = hex_digit_value(old_serial[2]) * 16 + hex_digit_value(old_serial[3]); system_serial[2] = hex_digit_value(old_serial[4]) * 16 + hex_digit_value(old_serial[5]); system_serial[3] = hex_digit_value(old_serial[6]) * 16 + hex_digit_value(old_serial[7]); system_serial[4] = hex_digit_value(old_serial[8]) * 16 + hex_digit_value(old_serial[9]); system_serial[5] = hex_digit_value(old_serial[10]) * 16 + hex_digit_value(old_serial[11]); system_serial[6] = hex_digit_value(old_serial[12]) * 16 + hex_digit_value(old_serial[13]); system_serial[7] = hex_digit_value(old_serial[14]) * 16 + hex_digit_value(old_serial[15]); // Here we need to do the reverse of the bit rotation below addr[0] = (system_serial[7] & 0x3f) << 2; system_serial[7] >>= 6; system_serial[7] |= (system_serial[6] & 0x3f) << 2; system_serial[6] >>= 6; system_serial[6] |= (system_serial[5] & 0x3f) << 2; system_serial[5] >>= 6; system_serial[5] |= addr[0]; } else {
bool CTxEthernetDataStore::parseForMessage(xmlNodePtr ptrNode, ETHERNET_FRAME_DATA& ouData) { if ( ptrNode == NULL) { return false; } else { //Name xmlChar* pchPathMsg = (xmlChar*)DEF_NAME; xmlXPathObjectPtr pObjectPath = xmlUtils::pGetChildNodes(ptrNode, pchPathMsg); if (pObjectPath != NULL ) { xmlNodeSetPtr pNodeSet = pObjectPath->nodesetval; if( NULL != pNodeSet ) { xmlNodePtr pNode = pNodeSet->nodeTab[0]; //Take First One only xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode , 1); ouData.m_strFrameName = (char*)key; } } //Channel pchPathMsg = (xmlChar*)DEF_CHANNEL; pObjectPath = xmlUtils::pGetChildNodes(ptrNode, pchPathMsg); if (pObjectPath != NULL ) { xmlNodeSetPtr pNodeSet = pObjectPath->nodesetval; if( NULL != pNodeSet ) { xmlNodePtr pNode = pNodeSet->nodeTab[0]; //Take First One only xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode , 1); ouData.m_ouEthernetMessage.m_ucChannel = atoi((char*)key); } } //Message ID pchPathMsg = (xmlChar*)DEF_MESSAGE_ID; pObjectPath = xmlUtils::pGetChildNodes(ptrNode, pchPathMsg); if (pObjectPath != NULL ) { xmlNodeSetPtr pNodeSet = pObjectPath->nodesetval; if( NULL != pNodeSet ) { xmlNodePtr pNode = pNodeSet->nodeTab[0]; //Take First One only xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode , 1); ouData.m_ouEthernetMessage.m_unMsgID = atoi((char*)key); } } //Protocol name pchPathMsg = (xmlChar*)DEF_PROTOCOL_NAME; pObjectPath = xmlUtils::pGetChildNodes(ptrNode, pchPathMsg); if (pObjectPath != NULL ) { xmlNodeSetPtr pNodeSet = pObjectPath->nodesetval; if( NULL != pNodeSet ) { xmlNodePtr pNode = pNodeSet->nodeTab[0]; //Take First One only xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode , 1); memcpy(ouData.m_ouEthernetMessage.m_ucProtocolName, key, sizeof(key)); } } //Source MAC pchPathMsg = (xmlChar*)DEF_SOURCE_MAC; pObjectPath = xmlUtils::pGetChildNodes(ptrNode, pchPathMsg); if (pObjectPath != NULL ) { xmlNodeSetPtr pNodeSet = pObjectPath->nodesetval; if( NULL != pNodeSet ) { xmlNodePtr pNode = pNodeSet->nodeTab[0]; //Take First One only xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode , 1); strcpy((char*)ouData.m_ouEthernetMessage.m_ucSourceMAC, (char*)key); } } //Destination MAC pchPathMsg = (xmlChar*)DEF_DEST_MAC; pObjectPath = xmlUtils::pGetChildNodes(ptrNode, pchPathMsg); if (pObjectPath != NULL ) { xmlNodeSetPtr pNodeSet = pObjectPath->nodesetval; if( NULL != pNodeSet ) { xmlNodePtr pNode = pNodeSet->nodeTab[0]; //Take First One only xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode , 1); strcpy((char*)ouData.m_ouEthernetMessage.m_ucDestMac, (char*)key); } } //DLC pchPathMsg = (xmlChar*)DEF_DLC; pObjectPath = xmlUtils::pGetChildNodes(ptrNode, pchPathMsg); if (pObjectPath != NULL ) { xmlNodeSetPtr pNodeSet = pObjectPath->nodesetval; if( NULL != pNodeSet ) { xmlNodePtr pNode = pNodeSet->nodeTab[0]; //Take First One only xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode , 1); ouData.m_ouEthernetMessage.m_unDataLen = atoi((char*)key); } } //DataBytes pchPathMsg = (xmlChar*)DEF_DATABYTES; pObjectPath = xmlUtils::pGetChildNodes(ptrNode, pchPathMsg); if (pObjectPath != NULL ) { xmlNodeSetPtr pNodeSet = pObjectPath->nodesetval; if( NULL != pNodeSet ) { xmlNodePtr pNode = pNodeSet->nodeTab[0]; //Take First One only xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode , 1); char* pch; pch = strtok ((char*)key," ,.-"); int i =0; while (pch != NULL) { ouData.m_ouEthernetMessage.m_ucData[i] = (hex_digit_value(pch[0]) << 4) | ( hex_digit_value(pch[1])); pch = strtok (NULL, " ,.-"); i++; } } } //Repetition pchPathMsg = (xmlChar*)DEF_REPETION; pObjectPath = xmlUtils::pGetChildNodes(ptrNode, pchPathMsg); if (pObjectPath != NULL ) { xmlNodeSetPtr pNodeSet = pObjectPath->nodesetval; if( NULL != pNodeSet ) { xmlNodePtr pNode = pNodeSet->nodeTab[0]; //Take First One only xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode , 1); ouData.nActualTimer = atoi((char*)key); ouData.nCurrentTimerVal = ouData.nActualTimer; } } //Repetition Enabled pchPathMsg = (xmlChar*)DEF_REPETITION_ENABLED; pObjectPath = xmlUtils::pGetChildNodes(ptrNode, pchPathMsg); if (pObjectPath != NULL ) { xmlNodeSetPtr pNodeSet = pObjectPath->nodesetval; if( NULL != pNodeSet ) { xmlNodePtr pNode = pNodeSet->nodeTab[0]; //Take First One only xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode , 1); ouData.m_bTimerEnabled = true; if ( strcmp((char*)key, "FALSE" ) == 0 ) { ouData.m_bTimerEnabled = false; } } } //Key Value pchPathMsg = (xmlChar*)DEF_KEY_VAL; pObjectPath = xmlUtils::pGetChildNodes(ptrNode, pchPathMsg); if (pObjectPath != NULL ) { xmlNodeSetPtr pNodeSet = pObjectPath->nodesetval; if( NULL != pNodeSet ) { xmlNodePtr pNode = pNodeSet->nodeTab[0]; //Take First One only xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode , 1); ouData.m_chKeyVal = ((char*)key)[0]; } } //Key Value Enabled pchPathMsg = (xmlChar*)DEF_KEY_ENABLED; pObjectPath = xmlUtils::pGetChildNodes(ptrNode, pchPathMsg); if (pObjectPath != NULL ) { xmlNodeSetPtr pNodeSet = pObjectPath->nodesetval; if( NULL != pNodeSet ) { xmlNodePtr pNode = pNodeSet->nodeTab[0]; //Take First One only xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode , 1); ouData.bKeyEnabled = true; if ( strcmp((char*)key, "FALSE" ) == 0 ) { ouData.bKeyEnabled = false; } } } //Enabled pchPathMsg = (xmlChar*)DEF_ENABLED; pObjectPath = xmlUtils::pGetChildNodes(ptrNode, pchPathMsg); if (pObjectPath != NULL ) { xmlNodeSetPtr pNodeSet = pObjectPath->nodesetval; if( NULL != pNodeSet ) { xmlNodePtr pNode = pNodeSet->nodeTab[0]; //Take First One only xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode , 1); ouData.bSelected = true; if ( strcmp((char*)key, "FALSE" ) == 0 ) { ouData.bSelected = false; } } } } return true; }