DyePalette::DyePalette(const std::string &description, const uint8_t blockSize) : mColors() { const size_t size = static_cast<size_t>(description.length()); if (size == 0) return; if (description[0] == '#') { size_t pos = 1; for ( ; ; ) { if (pos + blockSize > size) break; DyeColor color(0, 0, 0, 0); for (size_t i = 0, colorIdx = 0; i < blockSize && colorIdx < 4; i += 2, colorIdx ++) { color.value[colorIdx] = static_cast<unsigned char>(( hexDecode(description[pos + i]) << 4) + hexDecode(description[pos + i + 1])); } mColors.push_back(color); pos += blockSize; if (pos == size) return; if (description[pos] != ',') break; ++pos; } } #ifndef DYECMD else if (description[0] == '@') { size_t pos = 1; for ( ; pos < size ; ) { const size_t idx = description.find(',', pos); if (idx == std::string::npos) return; if (idx == pos) break; mColors.push_back(PaletteDB::getColor( description.substr(pos, idx - pos))); pos = idx + 1; } } #endif logger->log("Error, invalid embedded palette: %s", description.c_str()); }
void Packed::parseListBegin(char next) { m_bridge.mapListItem(hexDecode(m_name)); m_socket.putback(next); m_state.pop(); m_name.erase(); }
int main( int inNumArgs, char **inArgs ) { if( inNumArgs != 2 ) { usage(); } char *otherPublicKeyHex = inArgs[1]; if( strlen( otherPublicKeyHex ) != 64 ) { usage(); } unsigned char *otherPublicKey = hexDecode( otherPublicKeyHex ); if( otherPublicKey == NULL ) { usage(); } unsigned char secretKey[32]; unsigned char ourPublicKey[32]; unsigned char sharedSecretKey[32]; char gotRandom = getCryptoRandomBytes( secretKey, 32 ); if( !gotRandom ) { delete [] otherPublicKey; printf( "Failed to generate crypto-secure random bytes.\n" ); return 1; } curve25519_genPublicKey( ourPublicKey, secretKey ); curve25519_genSharedSecretKey( sharedSecretKey, secretKey, otherPublicKey ); char *ourPublicKeyHex = hexEncode( ourPublicKey, 32 ); char *sharedSecretKeyHex = hexEncode( sharedSecretKey, 32 ); printf( "%s\n%s\n", ourPublicKeyHex, sharedSecretKeyHex ); delete [] otherPublicKey; delete [] ourPublicKeyHex; delete [] sharedSecretKeyHex; return 0; }
void Packed::parseFloat(char next) { switch (next) { case '[': case ']': case '(': case ')': case '$': case '@': case '#': m_socket.putback(next); m_state.pop(); if (m_state.top() == PARSE_MAP) { m_bridge.mapFloatItem(hexDecode(m_name), atof(m_data.c_str())); m_name.erase(); } else if (m_state.top() == PARSE_LIST) { m_bridge.listFloatItem(atof(m_data.c_str())); } else { // FIXME some kind of sanity checking assertion here } m_data.erase(); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '.': case '-': case '+': case 'e': case 'E': m_data += next; break; default: // FIXME signal error here // unexpected character break; } }
void Packed::parseString(char next) { switch (next) { case '[': case ']': case '(': case ')': case '$': case '@': case '#': m_socket.putback(next); m_state.pop(); if (m_state.top() == PARSE_MAP) { m_bridge.mapStringItem(hexDecode(m_name), hexDecode(m_data)); m_name.erase(); } else if (m_state.top() == PARSE_LIST) { m_bridge.listStringItem(hexDecode(m_data)); } else { // FIXME some kind of sanity checking assertion here } m_data.erase(); break; case '=': // FIXME signal error here // unexpected character break; default: m_data += next; break; } }
GstStructure *payloadInfoToStructure(const PPayloadInfo &info, const QString &media) { GstStructure *out = gst_structure_empty_new("application/x-rtp"); { GValue gv; memset(&gv, 0, sizeof(GValue)); g_value_init(&gv, G_TYPE_STRING); g_value_set_string(&gv, media.toLatin1().data()); gst_structure_set_value(out, "media", &gv); } // payload id field required if(info.id == -1) { gst_structure_free(out); return 0; } { GValue gv; memset(&gv, 0, sizeof(GValue)); g_value_init(&gv, G_TYPE_INT); g_value_set_int(&gv, info.id); gst_structure_set_value(out, "payload", &gv); } // name required for payload values 96 or greater if(info.id >= 96 && info.name.isEmpty()) { gst_structure_free(out); return 0; } { GValue gv; memset(&gv, 0, sizeof(GValue)); g_value_init(&gv, G_TYPE_STRING); g_value_set_string(&gv, info.name.toLatin1().data()); gst_structure_set_value(out, "encoding-name", &gv); } if(info.clockrate != -1) { GValue gv; memset(&gv, 0, sizeof(GValue)); g_value_init(&gv, G_TYPE_INT); g_value_set_int(&gv, info.clockrate); gst_structure_set_value(out, "clock-rate", &gv); } if(info.channels != -1) { GValue gv; memset(&gv, 0, sizeof(GValue)); g_value_init(&gv, G_TYPE_STRING); g_value_set_string(&gv, QString::number(info.channels).toLatin1().data()); gst_structure_set_value(out, "encoding-params", &gv); } foreach(const PPayloadInfo::Parameter &i, info.parameters) { QString value = i.value; // FIXME: is there a better way to detect when we should do this conversion? if(i.name == "configuration" && (info.name.toUpper() == "THEORA" || info.name.toUpper() == "VORBIS")) { QByteArray config = hexDecode(value); if(config.isEmpty()) { gst_structure_free(out); return 0; } value = QString::fromLatin1(config.toBase64()); } GValue gv; memset(&gv, 0, sizeof(GValue)); g_value_init(&gv, G_TYPE_STRING); g_value_set_string(&gv, value.toLatin1().data()); gst_structure_set_value(out, i.name.toLatin1().data(), &gv); } return out; }