/** * librdf_new_uri2: * @world: redland world object * @uri_string: URI in string form * @length: length of string * * Constructor - create a new #librdf_uri object from a counted URI string. * * A new URI is constructed from a copy of the string. If the string * is a NULL pointer or 0 length or empty (first byte is 0) then the * result is NULL. * * Return value: a new #librdf_uri object or NULL on failure **/ librdf_uri* librdf_new_uri2(librdf_world *world, const unsigned char *uri_string, size_t length) { return raptor_new_uri_from_counted_string(world->raptor_world_ptr, uri_string, length); }
/** * raptor_new_term_from_counted_uri_string: * @world: raptor world * @uri_string: UTF-8 encoded URI string. * @length: length of URI string * * Constructor - create a new URI statement term from a UTF-8 encoded Unicode string * * Note: The @uri_string need not be NULL terminated - a NULL will be * added to the copied string used. * * Return value: new term or NULL on failure */ raptor_term* raptor_new_term_from_counted_uri_string(raptor_world* world, const unsigned char *uri_string, size_t length) { raptor_term *t; raptor_uri* uri; RAPTOR_CHECK_CONSTRUCTOR_WORLD(world); uri = raptor_new_uri_from_counted_string(world, uri_string, length); if(!uri) return NULL; t = raptor_new_term_from_uri(world, uri); raptor_free_uri(uri); return t; }
static void raptor_librdfa_generate_statement(rdftriple* triple, void* callback_data) { raptor_parser* parser = (raptor_parser*)callback_data; raptor_statement *s = &parser->statement; raptor_term *subject_term = NULL; raptor_term *predicate_term = NULL; raptor_uri *predicate_uri = NULL; raptor_term *object_term = NULL; if(!parser->emitted_default_graph) { raptor_parser_start_graph(parser, NULL, 0); parser->emitted_default_graph++; } if(!parser->statement_handler) goto cleanup; if(!triple->subject || !triple->predicate || !triple->object) { #ifdef RAPTOR_DEBUG RAPTOR_FATAL1("Triple has NULL parts\n"); #else rdfa_free_triple(triple); return; #endif } if(triple->predicate[0] == '_') { raptor_parser_warning(parser, "Ignoring RDFa triple with blank node predicate %s.", triple->predicate); rdfa_free_triple(triple); return; } if(triple->object_type == RDF_TYPE_NAMESPACE_PREFIX) { #ifdef RAPTOR_DEBUG RAPTOR_FATAL1("Triple has namespace object type\n"); #else rdfa_free_triple(triple); return; #endif } if((triple->subject[0] == '_') && (triple->subject[1] == ':')) { subject_term = raptor_new_term_from_blank(parser->world, (const unsigned char*)triple->subject + 2); } else { raptor_uri* subject_uri; subject_uri = raptor_new_uri(parser->world, (const unsigned char*)triple->subject); subject_term = raptor_new_term_from_uri(parser->world, subject_uri); raptor_free_uri(subject_uri); subject_uri = NULL; } s->subject = subject_term; predicate_uri = raptor_new_uri(parser->world, (const unsigned char*)triple->predicate); if(!predicate_uri) goto cleanup; predicate_term = raptor_new_term_from_uri(parser->world, predicate_uri); raptor_free_uri(predicate_uri); predicate_uri = NULL; s->predicate = predicate_term; if(triple->object_type == RDF_TYPE_IRI) { if((triple->object[0] == '_') && (triple->object[1] == ':')) { object_term = raptor_new_term_from_blank(parser->world, (const unsigned char*)triple->object + 2); } else { raptor_uri* object_uri; object_uri = raptor_new_uri(parser->world, (const unsigned char*)triple->object); if(!object_uri) goto cleanup; object_term = raptor_new_term_from_uri(parser->world, object_uri); raptor_free_uri(object_uri); } } else if(triple->object_type == RDF_TYPE_PLAIN_LITERAL) { object_term = raptor_new_term_from_literal(parser->world, (const unsigned char*)triple->object, NULL, (const unsigned char*)triple->language); } else if(triple->object_type == RDF_TYPE_XML_LITERAL) { raptor_uri* datatype_uri; datatype_uri = raptor_new_uri_from_counted_string(parser->world, (const unsigned char*)raptor_xml_literal_datatype_uri_string, raptor_xml_literal_datatype_uri_string_len); object_term = raptor_new_term_from_literal(parser->world, (const unsigned char*)triple->object, datatype_uri, NULL); raptor_free_uri(datatype_uri); } else if(triple->object_type == RDF_TYPE_TYPED_LITERAL) { raptor_uri *datatype_uri = NULL; const unsigned char* language = (const unsigned char*)triple->language; if(triple->datatype) { /* If datatype, no language allowed */ language = NULL; datatype_uri = raptor_new_uri(parser->world, (const unsigned char*)triple->datatype); if(!datatype_uri) goto cleanup; } object_term = raptor_new_term_from_literal(parser->world, (const unsigned char*)triple->object, datatype_uri, language); raptor_free_uri(datatype_uri); } else { raptor_log_error_formatted(parser->world, RAPTOR_LOG_LEVEL_ERROR, NULL, "Triple has unknown object term type %u", s->object->type); goto cleanup; } s->object = object_term; /* Generate statement */ (*parser->statement_handler)(parser->user_data, s); cleanup: rdfa_free_triple(triple); if(subject_term) raptor_free_term(subject_term); if(predicate_term) raptor_free_term(predicate_term); if(object_term) raptor_free_term(object_term); }
/** * librdf_new_uri2: * @world: redland world object * @uri_string: URI in string form * @length: length of string * * Constructor - create a new #librdf_uri object from a counted URI string. * * A new URI is constructed from a copy of the string. If the string * is a NULL pointer or 0 length or empty (first byte is 0) then the * result is NULL. * * Return value: a new #librdf_uri object or NULL on failure **/ librdf_uri* librdf_new_uri2(librdf_world *world, const unsigned char *uri_string, size_t length) { #ifdef LIBRDF_USE_RAPTOR_URI return raptor_new_uri_from_counted_string(world->raptor_world_ptr, uri_string, length); #else librdf_uri* new_uri; unsigned char *new_string; librdf_hash_datum key, value; /* on stack - not allocated */ librdf_hash_datum *old_value; /* just to be safe */ memset(&key, 0, sizeof(key)); memset(&value, 0, sizeof(value)); librdf_world_open(world); if(!uri_string || !length || !*uri_string) return NULL; #ifdef WITH_THREADS pthread_mutex_lock(world->mutex); #endif key.data = (char*)uri_string; key.size = length; /* if existing URI found in hash, return it */ if((old_value = librdf_hash_get_one(world->uris_hash, &key))) { new_uri = *(librdf_uri**)old_value->data; #if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 LIBRDF_DEBUG3("Found existing URI %s in hash with current usage %d\n", uri_string, new_uri->usage); #endif librdf_free_hash_datum(old_value); new_uri->usage++; #if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 if(new_uri->usage > new_uri->max_usage) new_uri->max_usage = new_uri->usage; #endif goto unlock; } /* otherwise create a new one */ #if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 LIBRDF_DEBUG2("Creating new URI %s in hash\n", uri_string); #endif new_uri = (librdf_uri*)LIBRDF_CALLOC(librdf_uri, 1, sizeof(librdf_uri)); if(!new_uri) goto unlock; new_uri->world = world; new_uri->string_length = length; new_string = (unsigned char*)LIBRDF_MALLOC(cstring, length+1); if(!new_string) { LIBRDF_FREE(librdf_uri, new_uri); new_uri = NULL; goto unlock; } strcpy((char*)new_string, (const char*)uri_string); new_uri->string = new_string; new_uri->usage = 1; #if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 new_uri->max_usage = 1; #endif value.data = &new_uri; value.size = sizeof(librdf_uri*); /* store in hash: URI-string => (librdf_uri*) */ if(librdf_hash_put(world->uris_hash, &key, &value)) { LIBRDF_FREE(cstring, new_string); LIBRDF_FREE(librdf_uri, new_uri); new_uri = NULL; } unlock: #ifdef WITH_THREADS pthread_mutex_unlock(world->mutex); #endif return new_uri; #endif /* !LIBRDF_USE_RAPTOR_URI */ }