ExtractionWay XMLParser::_ReadXMLWay() { ExtractionWay way; if ( xmlTextReaderIsEmptyElement( inputReader ) != 1 ) { const int depth = xmlTextReaderDepth( inputReader ); while ( xmlTextReaderRead( inputReader ) == 1 ) { const int childType = xmlTextReaderNodeType( inputReader ); if ( childType != 1 && childType != 15 ) { continue; } const int childDepth = xmlTextReaderDepth( inputReader ); xmlChar* childName = xmlTextReaderName( inputReader ); if ( childName == NULL ) { continue; } if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "way" ) == 1 ) { xmlChar* id = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "id" ); way.id = stringToUint((char*)id); xmlFree(id); xmlFree( childName ); break; } if ( childType != 1 ) { xmlFree( childName ); continue; } if ( xmlStrEqual( childName, ( const xmlChar* ) "tag" ) == 1 ) { xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" ); xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" ); // cout << "->k=" << k << ", v=" << value << endl; if ( k != NULL && value != NULL ) { way.keyVals.Add(std::string( (char *) k ), std::string( (char *) value)); } if ( k != NULL ) { xmlFree( k ); } if ( value != NULL ) { xmlFree( value ); } } else if ( xmlStrEqual( childName, ( const xmlChar* ) "nd" ) == 1 ) { xmlChar* ref = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "ref" ); if ( ref != NULL ) { way.path.push_back( stringToUint(( const char* ) ref ) ); xmlFree( ref ); } } xmlFree( childName ); } } return way; }
unsigned int lms_verify_signature(char* sig, char* public_key, char* message, unsigned int mes_len) { lms_sig_t lms_signature; lm_ots_sig_t decoded_sig; unsigned int node_num = 0; list_node_t* temp_node = NULL; char temp_input[N + ENTROPY_SIZE + 4 + 1] = {0}; char temp_string[5] = {0}; char temp[N + N + ENTROPY_SIZE + 4 + 1] = {0}; char* lm_ots_sig = NULL; decode_lms_sig(sig, &lms_signature); temp_node = lms_signature.path; decode_lmots_sig(lms_signature.lm_ots_sig,&decoded_sig);// note: only q is actually needed here node_num = stringToUint((unsigned char*)decoded_sig.q,4) + NUM_LEAF_NODES; lm_ots_sig = lmots_sig_to_public_key(lms_signature.lm_ots_sig, message,mes_len); memcpy(temp_input,lm_ots_sig,N*sizeof(char)); memcpy(temp_input + N,decoded_sig.I,ENTROPY_SIZE*sizeof(char)); memcpy(temp_input + (N + ENTROPY_SIZE),uint32ToString(node_num,temp_string),4*sizeof(char)); memcpy(temp_input + (N + ENTROPY_SIZE + 4)*sizeof(char),uint8ToString(D_LEAF,temp_string),1); H(temp_input,temp_input,N + ENTROPY_SIZE + 4 + 1); memcpy(temp,temp_input,N); while(node_num > 1) { //printf("S(%d):\t %s \n ",node_num, stringToHex(temp_input,N)); //printf("temp_node %p \n ",temp_node); //printf("data %s %d \n ",stringToHex(temp_node->data,N),node_num); if (node_num % 2) { //print "adding node " + str(node_num - 1) memcpy(temp,temp_node->data,N*sizeof(char)); memcpy(temp + N ,temp_input,N*sizeof(char)); memcpy(temp + N + N,decoded_sig.I,ENTROPY_SIZE*sizeof(char)); memcpy(temp + N + N + ENTROPY_SIZE,uint32ToString(node_num/2,temp_string),4*sizeof(char)); memcpy(temp + N + N + ENTROPY_SIZE + 4 ,uint8ToString(D_INTR,temp_string),1); //printf("INPUT: %s \n ",stringToHex(temp, 2*N +36)); H(temp,temp_input, N + N + ENTROPY_SIZE + 4 + 1); } else { // print "adding node " + str(node_num + 1) memcpy(temp + N ,temp_node->data,N*sizeof(char)); memcpy(temp + N + N,decoded_sig.I,ENTROPY_SIZE*sizeof(char)); memcpy(temp + N + N + ENTROPY_SIZE,uint32ToString(node_num/2,temp_string),4*sizeof(char)); memcpy(temp + N + N + ENTROPY_SIZE + 4,uint8ToString(D_INTR,temp_string),1); //printf("INPUT: %s \n ",stringToHex(temp, 2*N +36)); H(temp,temp_input, N + N + ENTROPY_SIZE + 4 + 1); } memcpy(temp,temp_input,N); node_num = node_num/2; temp_node = temp_node->next; } /* Clean up the allocated data */ free(lm_ots_sig); free(lms_signature.lm_ots_sig); cleanup_link_list(lms_signature.path); cleanup_link_list(decoded_sig.y); D(printf("GEN PUB: %s \n",stringToHex(temp,N));)
void Controller::fillPoolOption(Request *req, unsigned long &field, const HashedStaticString &name) { const LString *value = req->secureHeaders.lookup(name); if (value != NULL && value->size > 0) { value = psg_lstr_make_contiguous(value, req->pool); field = stringToUint(StaticString(value->start->data, value->size)); } }
void parseTcpSocketAddress(const StaticString &address, string &host, unsigned short &port) { if (getSocketAddressType(address) != SAT_TCP) { throw ArgumentException("Not a valid TCP socket address"); } StaticString hostAndPort(address.data() + sizeof("tcp://") - 1, address.size() - sizeof("tcp://") + 1); if (hostAndPort.empty()) { throw ArgumentException("Not a valid TCP socket address"); } if (hostAndPort[0] == '[') { // IPv6 address, e.g.: // [::1]:3000 const char *hostEnd = (const char *) memchr(hostAndPort.data(), ']', hostAndPort.size()); if (hostEnd == NULL || hostAndPort.size() <= string::size_type(hostEnd - hostAndPort.data()) + 3) { throw ArgumentException("Not a valid TCP socket address"); } const char *sep = hostEnd + 1; host.assign(hostAndPort.data() + 1, hostEnd - hostAndPort.data() - 1); port = stringToUint(StaticString( sep + 1, hostAndPort.data() + hostAndPort.size() - sep - 1 )); } else { // IPv4 address, e.g.: // 127.0.0.1:3000 const char *sep = (const char *) memchr(hostAndPort.data(), ':', hostAndPort.size()); if (sep == NULL || hostAndPort.size() <= string::size_type(sep - hostAndPort.data()) + 2) { throw ArgumentException("Not a valid TCP socket address"); } host.assign(hostAndPort.data(), sep - hostAndPort.data()); port = stringToUint(StaticString( sep + 1, hostAndPort.data() + hostAndPort.size() - sep - 1 )); } }
static void getSvgAttributes(xmlTextReaderPtr const xmlReaderP, unsigned int * const colsP, unsigned int * const rowsP) { const char * const width = getAttribute(xmlReaderP, "width"); const char * const height = getAttribute(xmlReaderP, "height"); const char * error; stringToUint(width, colsP, &error); if (error) { pm_error("'width' attribute of <svg> has invalid value. %s", error); strfree(error); } stringToUint(height, rowsP, &error); if (error) { pm_error("'height' attribute of <svg> has invalid value. %s", error); strfree(error); } }
void Controller::setStickySessionId(Client *client, Request *req) { if (req->stickySession) { // TODO: This is not entirely correct. Clients MAY send multiple Cookie // headers, although this is in practice extremely rare. // http://stackoverflow.com/questions/16305814/are-multiple-cookie-headers-allowed-in-an-http-request const LString *cookieHeader = req->headers.lookup(HTTP_COOKIE); if (cookieHeader != NULL && cookieHeader->size > 0) { const LString *cookieName = getStickySessionCookieName(req); vector< pair<StaticString, StaticString> > cookies; pair<StaticString, StaticString> cookie; parseCookieHeader(req->pool, cookieHeader, cookies); foreach (cookie, cookies) { if (psg_lstr_cmp(cookieName, cookie.first)) { // This cookie matches the one we're looking for. req->options.stickySessionId = stringToUint(cookie.second); return; } } } } }
InputRestrictionContainer XMLParser::_ReadXMLRestriction() { InputRestrictionContainer restriction; std::string except_tag_string; if ( xmlTextReaderIsEmptyElement( inputReader ) != 1 ) { const int depth = xmlTextReaderDepth( inputReader );while ( xmlTextReaderRead( inputReader ) == 1 ) { const int childType = xmlTextReaderNodeType( inputReader ); if ( childType != 1 && childType != 15 ) { continue; } const int childDepth = xmlTextReaderDepth( inputReader ); xmlChar* childName = xmlTextReaderName( inputReader ); if ( childName == NULL ) { continue; } if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "relation" ) == 1 ) { xmlFree( childName ); break; } if ( childType != 1 ) { xmlFree( childName ); continue; } if ( xmlStrEqual( childName, ( const xmlChar* ) "tag" ) == 1 ) { xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" ); xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" ); if ( k != NULL && value != NULL ) { if(xmlStrEqual(k, ( const xmlChar* ) "restriction" )){ if(0 == std::string((const char *) value).find("only_")) { restriction.restriction.flags.isOnly = true; } } if ( xmlStrEqual(k, (const xmlChar *) "except") ) { except_tag_string = (const char*) value; } } if ( k != NULL ) { xmlFree( k ); } if ( value != NULL ) { xmlFree( value ); } } else if ( xmlStrEqual( childName, ( const xmlChar* ) "member" ) == 1 ) { xmlChar* ref = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "ref" ); if ( ref != NULL ) { xmlChar * role = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "role" ); xmlChar * type = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "type" ); if(xmlStrEqual(role, (const xmlChar *) "to") && xmlStrEqual(type, (const xmlChar *) "way")) { restriction.toWay = stringToUint((const char*) ref); } if(xmlStrEqual(role, (const xmlChar *) "from") && xmlStrEqual(type, (const xmlChar *) "way")) { restriction.fromWay = stringToUint((const char*) ref); } if(xmlStrEqual(role, (const xmlChar *) "via") && xmlStrEqual(type, (const xmlChar *) "node")) { restriction.restriction.viaNode = stringToUint((const char*) ref); } if(NULL != type) { xmlFree( type ); } if(NULL != role) { xmlFree( role ); } if(NULL != ref) { xmlFree( ref ); } } } xmlFree( childName ); } } if( ShouldIgnoreRestriction(except_tag_string) ) { restriction.fromWay = UINT_MAX; //workaround to ignore the restriction } return restriction; }
ImportNode XMLParser::_ReadXMLNode() { ImportNode node; xmlChar* attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "lat" ); if ( attribute != NULL ) { node.lat = static_cast<NodeID>(COORDINATE_PRECISION*atof(( const char* ) attribute ) ); xmlFree( attribute ); } attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "lon" ); if ( attribute != NULL ) { node.lon = static_cast<NodeID>(COORDINATE_PRECISION*atof(( const char* ) attribute )); xmlFree( attribute ); } attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "id" ); if ( attribute != NULL ) { node.id = stringToUint(( const char* ) attribute ); xmlFree( attribute ); } if ( xmlTextReaderIsEmptyElement( inputReader ) != 1 ) { const int depth = xmlTextReaderDepth( inputReader ); while ( xmlTextReaderRead( inputReader ) == 1 ) { const int childType = xmlTextReaderNodeType( inputReader ); // 1 = Element, 15 = EndElement if ( childType != 1 && childType != 15 ) { continue; } const int childDepth = xmlTextReaderDepth( inputReader ); xmlChar* childName = xmlTextReaderName( inputReader ); if ( childName == NULL ) { continue; } if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "node" ) == 1 ) { xmlFree( childName ); break; } if ( childType != 1 ) { xmlFree( childName ); continue; } if ( xmlStrEqual( childName, ( const xmlChar* ) "tag" ) == 1 ) { xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" ); xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" ); if ( k != NULL && value != NULL ) { node.keyVals.Add(std::string( reinterpret_cast<char*>(k) ), std::string( reinterpret_cast<char*>(value))); } if ( k != NULL ) { xmlFree( k ); } if ( value != NULL ) { xmlFree( value ); } } xmlFree( childName ); } } return node; }