static int assert_uri_to_relative(const char *base, const char *uri, const char *relative) { unsigned char *output; int result; raptor_uri* base_uri=NULL; raptor_uri* reference_uri=raptor_new_uri((const unsigned char*)uri); size_t length=0; if(base) base_uri=raptor_new_uri((const unsigned char*)base); output=raptor_uri_to_relative_counted_uri_string(base_uri, reference_uri, &length); result=strcmp(relative, (const char*)output); if (result) { fprintf(stderr, "%s: raptor_uri_string_to_relative_uri_string FAILED: base='%s', uri='%s', expected='%s', got='%s'\n", program, base, uri, relative, output); RAPTOR_FREE(cstring, output); return 1; } RAPTOR_FREE(cstring, output); raptor_free_uri(base_uri); raptor_free_uri(reference_uri); return 0; }
bool UTOPIASerializer::serialize(Serializer::Context& ctx, QIODevice& stream_, Node* node_) const { QMap< Node*, int > nodeIDs; raptor_iostream_handler2 QIODeviceHandler = { 2, qiodevice_iostream_init, qiodevice_iostream_finish, qiodevice_iostream_write_byte, qiodevice_iostream_write_bytes, qiodevice_iostream_write_end, 0, 0 }; // FIXME base uri? // raptor_uri* base_uri = raptor_new_uri((const unsigned char*) "HAHAHA"); // raptor_serializer* rdf_serializer = raptor_new_serializer("rdfxml"); raptor_serializer* rdf_serializer = raptor_new_serializer("ntriples"); raptor_iostream* qiodevice_iostream = raptor_new_iostream_from_handler2(&stream_, &QIODeviceHandler); raptor_serialize_set_namespace(rdf_serializer, raptor_new_uri((const unsigned char*) "http://utopia.cs.manchester.ac.uk/2007/03/utopia-system#"), (const unsigned char*) "system"); raptor_serialize_set_namespace(rdf_serializer, raptor_new_uri((const unsigned char*) "http://utopia.cs.manchester.ac.uk/2007/03/utopia-domain#"), (const unsigned char*) "domain"); raptor_serialize_start(rdf_serializer, 0 /*base_uri*/, qiodevice_iostream); serialiseNode(rdf_serializer, nodeIDs, node_, true); raptor_serialize_end(rdf_serializer); return true; }
/** * raptor_new_turtle_writer: * @world: raptor_world object * @base_uri: Base URI for the writer (or NULL) * @write_base_uri: non-0 to write '@base' directive to output * @nstack: Namespace stack for the writer to start with (or NULL) * @iostr: I/O stream to write to * * Constructor - Create a new Turtle Writer writing Turtle to a raptor_iostream * * Return value: a new #raptor_turtle_writer object or NULL on failure **/ raptor_turtle_writer* raptor_new_turtle_writer(raptor_world* world, raptor_uri* base_uri, int write_base_uri, raptor_namespace_stack *nstack, raptor_iostream* iostr) { raptor_turtle_writer* turtle_writer; RAPTOR_CHECK_CONSTRUCTOR_WORLD(world); if(!nstack || !iostr) return NULL; raptor_world_open(world); turtle_writer = (raptor_turtle_writer*)RAPTOR_CALLOC(raptor_turtle_writer, 1, sizeof(*turtle_writer)); if(!turtle_writer) return NULL; turtle_writer->world = world; turtle_writer->nstack_depth = 0; turtle_writer->nstack = nstack; if(!turtle_writer->nstack) { turtle_writer->nstack = raptor_new_namespaces(world, 1); turtle_writer->my_nstack = 1; } turtle_writer->iostr = iostr; turtle_writer->flags = 0; turtle_writer->indent = 2; turtle_writer->base_uri = NULL; /* Ensure any initial base URI is not written relative */ if(base_uri && write_base_uri) raptor_turtle_writer_base(turtle_writer, base_uri); turtle_writer->base_uri = base_uri; turtle_writer->xsd_boolean_uri = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#boolean"); turtle_writer->xsd_decimal_uri = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#decimal"); turtle_writer->xsd_double_uri = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#double"); turtle_writer->xsd_integer_uri = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#integer"); return turtle_writer; }
int main(int argc, char *argv[]) { #ifdef HAVE_RAPTOR raptor_world *world = NULL; raptor_parser* rdf_parser = NULL; unsigned char *uri_string; raptor_uri *uri, *base_uri; world = raptor_new_world(); rdf_parser = raptor_new_parser(world, "ntriples"); raptor_parser_set_statement_handler(rdf_parser, NULL, print_triple); uri_string = raptor_uri_filename_to_uri_string(argv[1]); uri = raptor_new_uri(world, uri_string); base_uri = raptor_uri_copy(uri); raptor_parser_parse_file(rdf_parser, uri, base_uri); raptor_free_parser(rdf_parser); raptor_free_uri(base_uri); raptor_free_uri(uri); raptor_free_memory(uri_string); raptor_free_world(world); #endif return EXIT_SUCCESS; }
DllExport int call_conv load_nquad_file(CTXTdecl) { char *filename = p2c_string(reg_term(CTXTdecl 1)); unsigned char *uri_string; raptor_uri *uri, *base_uri; world = raptor_new_world(); rdf_parser = raptor_new_parser(world, "nquads"); raptor_parser_set_statement_handler(rdf_parser, NULL, handle_term); uri_string = raptor_uri_filename_to_uri_string(filename); uri = raptor_new_uri(world, uri_string); base_uri = raptor_uri_copy(uri); raptor_parser_parse_file(rdf_parser, uri, base_uri); raptor_free_parser(rdf_parser); raptor_free_uri(base_uri); raptor_free_uri(uri); raptor_free_memory(uri_string); raptor_free_world(world); return 1; }
/** * raptor_new_uri_for_retrieval - Turn a URI into one suitable for retrieval * @old_uri: URI to transform * * Takes an existing URI and ensures it has a path (default /) and has * no fragment - URI retrieval does not use the fragment part. * * Return value: new URI object or NULL on failure. **/ raptor_uri* raptor_new_uri_for_retrieval(raptor_uri* old_uri) { unsigned char *uri_string=raptor_uri_as_string(old_uri); unsigned char *buffer; size_t buffer_len=strlen((const char*)uri_string)+1; unsigned char *scheme; unsigned char *authority; unsigned char *path; unsigned char *query; unsigned char *fragment; unsigned char *new_uri_string; raptor_uri* new_uri; buffer=(unsigned char*)RAPTOR_MALLOC(cstring, buffer_len); if(!buffer) return NULL; raptor_uri_parse (uri_string, buffer, buffer_len, &scheme, &authority, &path, &query, &fragment); if(!path) path=(unsigned char*)"/"; new_uri_string=raptor_uri_construct(scheme, authority, path, query, NULL); RAPTOR_FREE(cstring, buffer); if(!new_uri_string) return NULL; new_uri=raptor_new_uri(new_uri_string); RAPTOR_FREE(cstring, new_uri_string); return new_uri; }
/** * raptor_new_uri_for_retrieval: * @old_uri: URI to transform * * Constructor - create a URI suitable for retrieval. * * Takes an existing URI and ensures it has a path (default /) and has * no fragment - URI retrieval does not use the fragment part. * * Return value: new #raptor_uri object or NULL on failure. **/ raptor_uri* raptor_new_uri_for_retrieval(raptor_uri* old_uri) { unsigned char *uri_string; unsigned char *new_uri_string; raptor_uri* new_uri; raptor_uri_detail *ud; if(!old_uri) return NULL; uri_string=raptor_uri_as_string(old_uri); ud=raptor_new_uri_detail(uri_string); if(!ud) return NULL; if(!ud->path) { ud->path=(unsigned char*)"/"; ud->path_len=1; } ud->fragment=NULL; ud->fragment_len=0; new_uri_string=raptor_uri_detail_to_string(ud, NULL); raptor_free_uri_detail(ud); if(!new_uri_string) return NULL; new_uri=raptor_new_uri(new_uri_string); RAPTOR_FREE(cstring, new_uri_string); return new_uri; }
/** * raptor_serializer_start_to_filename: * @rdf_serializer: the #raptor_serializer * @filename: filename to serialize to * * Start serializing to a filename. * * Return value: non-0 on failure. **/ int raptor_serializer_start_to_filename(raptor_serializer *rdf_serializer, const char *filename) { unsigned char *uri_string = raptor_uri_filename_to_uri_string(filename); if(!uri_string) return 1; if(rdf_serializer->base_uri) raptor_free_uri(rdf_serializer->base_uri); rdf_serializer->base_uri = raptor_new_uri(rdf_serializer->world, uri_string); rdf_serializer->locator.uri = rdf_serializer->base_uri; rdf_serializer->locator.line = rdf_serializer->locator.column = 0; RAPTOR_FREE(char*, uri_string); rdf_serializer->iostream = raptor_new_iostream_to_filename(rdf_serializer->world, filename); if(!rdf_serializer->iostream) return 1; rdf_serializer->free_iostream_on_end = 1; if(rdf_serializer->factory->serialize_start) return rdf_serializer->factory->serialize_start(rdf_serializer); return 0; }
/***** ** Lee el archivo que contiene las tripletas RDF ** y hace el llamado a la funcion save_triple() para guardarlos *****/ void rdf_database_read_file(rdf_database db, const char *file) { raptor_world *world = NULL; unsigned char *uri_string; raptor_uri *uri, *base_uri; // parser world = raptor_new_world(); rdf_parser = raptor_new_parser(world, "rdfxml"); // seteo funcion handler para cada nodo raptor_parser_set_statement_handler(rdf_parser, (void*)db, save_triple); uri_string = raptor_uri_filename_to_uri_string(file); uri = raptor_new_uri(world, uri_string); base_uri = raptor_uri_copy(uri); // empieza parseo y guardado en memoria raptor_parser_parse_file(rdf_parser, uri, base_uri); // liberar ram raptor_free_parser(rdf_parser); raptor_free_uri(base_uri); raptor_free_uri(uri); raptor_free_memory(uri_string); raptor_free_world(world); }
static int raptor_rss_parse_init(raptor_parser* rdf_parser, const char *name) { raptor_rss_parser_context *rss_parser=(raptor_rss_parser_context*)rdf_parser->context; int i; RAPTOR_RDF_type_URI(rss_parser)=raptor_new_uri_for_rdf_concept("type"); RAPTOR_RDF_Seq_URI(rss_parser)=raptor_new_uri_for_rdf_concept("Seq"); for(i=0; i<RSS_NAMESPACES_SIZE;i++) { const char *uri_string=rss_namespace_uri_strings[i]; if(uri_string) rss_parser->namespace_uris[i]=raptor_new_uri((const unsigned char*)uri_string); } for(i=0; i< RAPTOR_RSS_COMMON_SIZE; i++) { raptor_uri *namespace_uri=rss_parser->namespace_uris[raptor_rss_types_info[i].nspace]; if(namespace_uri) raptor_rss_types_info[i].uri=raptor_new_uri_from_uri_local_name(namespace_uri, (const unsigned char*)raptor_rss_types_info[i].name); } for(i=0; i< RAPTOR_RSS_FIELDS_SIZE; i++) { raptor_uri *namespace_uri=rss_parser->namespace_uris[raptor_rss_fields_info[i].nspace]; if(namespace_uri) raptor_rss_fields_info[i].uri=raptor_new_uri_from_uri_local_name(namespace_uri, (const unsigned char*)raptor_rss_fields_info[i].name); } xmlSubstituteEntitiesDefault(1); return 0; }
int main(int argc, char *argv[]) { fsp_link *link; fs_query_state *qs; fs_query *qr; raptor_uri *bu; int i; #ifdef LINUX mtrace(); #endif link = fsp_open_link("ukgov_finances_cra", NULL, FS_OPEN_HINT_RW); raptor_init(); fs_hash_init(fsp_hash_type(link)); bu = raptor_new_uri((unsigned char *)"local:"); fsp_no_op(link, 0); qs = fs_query_init(link); for (i=0;i<atoi(argv[1]);i++) { //printf("--------- %d ----------\n", i); qr = fs_query_execute(qs, link, bu, QUERY, 0, 3, 0); fs_query_free(qr); fs_query_cache_flush(qs, 0); } fs_query_fini(qs); raptor_free_uri(bu); raptor_finish(); fsp_close_link(link); #ifdef LINUX muntrace(); #endif }
static void raptor_www_curl_update_status(raptor_www* www) { char* final_uri; if(www->failed) return; if(www->checked_status++) return; if(!www->final_uri) { /* If not already found in headers by * raptor_www_curl_header_callback() which overrides what libcurl * found in HTTP status line (3xx) */ if(curl_easy_getinfo(www->curl_handle, CURLINFO_EFFECTIVE_URL, &final_uri) == CURLE_OK) { www->final_uri = raptor_new_uri(www->world, (const unsigned char*)final_uri); if(www->final_uri_handler) www->final_uri_handler(www, www->final_uri_userdata, www->final_uri); } } }
int rasqal_xsd_init(rasqal_world* world) { int i; world->xsd_namespace_uri = raptor_new_uri(world->raptor_world_ptr, raptor_xmlschema_datatypes_namespace_uri); if(!world->xsd_namespace_uri) return 1; world->xsd_datatype_uris = (raptor_uri**)RASQAL_CALLOC(ptrarray, SPARQL_XSD_NAMES_COUNT + 1, sizeof(raptor_uri*)); if(!world->xsd_datatype_uris) return 1; for(i = RASQAL_LITERAL_FIRST_XSD; i < SPARQL_XSD_NAMES_COUNT; i++) { const unsigned char* name = (const unsigned char*)sparql_xsd_names[i]; world->xsd_datatype_uris[i] = raptor_new_uri_from_uri_local_name(world->raptor_world_ptr, world->xsd_namespace_uri, name); if(!world->xsd_datatype_uris[i]) return 1; } return 0; }
CRDFGraph * CRDFParser::parse(std::istream & stream) { bool success = true; bool done = false; stream.imbue(std::locale::classic()); stream.precision(16); // Create the new graph CRDFGraph * pGraph = new CRDFGraph; unsigned C_INT32 BUFFER_SIZE = 0xfffe; char * pBuffer = new char[BUFFER_SIZE + 1]; stream.get(pBuffer, BUFFER_SIZE, 0); if (stream.gcount() != 0) { raptor_uri * pURI = raptor_new_uri((unsigned char *) "#"); if (raptor_start_parse(mpParser, pURI)) fatalError(); raptor_set_statement_handler(mpParser, pGraph, &CRDFParser::TripleHandler); raptor_set_namespace_handler(mpParser, pGraph, &CRDFParser::NameSpaceHandler); raptor_set_generate_id_handler(mpParser, pGraph, &CRDFParser::GenerateIdHandler); while (!done) { if (stream.eof()) done = true; if (stream.fail() && !done) fatalError(); if (raptor_parse_chunk(mpParser, (unsigned char *) pBuffer, strlen(pBuffer), done ? 1 : 0)) { done = true; success = false; } stream.get(pBuffer, BUFFER_SIZE, 0); } } delete [] pBuffer; if (!success) { pdelete(pGraph); return NULL; } if (pGraph) pGraph->guessGraphRoot(); return pGraph; }
static void ser_emit_triple(void* user_data, const char* subject, int subject_type, const char* predicate_nspace, const char* predicate_name, const char *object, int object_type, const char *datatype_uri) { raptor_serializer* serializer = (raptor_serializer*)user_data; raptor_statement s; /* static */ raptor_uri* predicate_ns_uri; raptor_uri* predicate_uri; raptor_statement_init(&s, rworld); if(subject_type == FLICKCURL_TERM_TYPE_RESOURCE) s.subject = raptor_new_term_from_uri_string(rworld, (const unsigned char*)subject); else /* blank node */ s.subject = raptor_new_term_from_blank(rworld, (const unsigned char*)subject); predicate_ns_uri = raptor_new_uri(rworld, (const unsigned char*)predicate_nspace); predicate_uri = raptor_new_uri_from_uri_local_name(rworld, predicate_ns_uri, (const unsigned char*)predicate_name); s.predicate = raptor_new_term_from_uri(rworld, predicate_uri); raptor_free_uri(predicate_uri); raptor_free_uri(predicate_ns_uri); if(object_type == FLICKCURL_TERM_TYPE_RESOURCE) s.object = (void*)raptor_new_term_from_uri_string(rworld, (const unsigned char*)object); else if(object_type == FLICKCURL_TERM_TYPE_BLANK) s.object = raptor_new_term_from_blank(rworld, (const unsigned char*)subject); else { /* literal */ raptor_uri* raptor_datatype_uri = NULL; if(datatype_uri) raptor_datatype_uri = raptor_new_uri(rworld, (const unsigned char*)datatype_uri); s.object = raptor_new_term_from_literal(rworld, (const unsigned char*)object, raptor_datatype_uri, NULL /* language */); raptor_free_uri(raptor_datatype_uri); } raptor_serializer_serialize_statement(serializer, &s); raptor_statement_clear(&s); }
/* ..._start and ..._finish share an int * count parameter * the same variable should be passed by reference both times */ int fs_import_stream_start(fsp_link *link, const char *model_uri, const char *mimetype, int has_o_index, int *count) { if (inited == 0) { memset(&parse_data, 0, sizeof(parse_data)); inited = 1; } parse_data.link = link; parse_data.segments = fsp_link_segments(link); parse_data.ext_count = count; for (int i=0; i<parse_data.segments; i++) { for (int j=0; j<RES_BUF_SIZE; j++) { lex_tmp[i][j] = malloc(RES_BUF_SIZE); } } memset(nodecache, 0, sizeof(nodecache)); parse_data.quad_fn = g_strdup(FS_TMP_PATH "/importXXXXXX"); parse_data.quad_fd = mkstemp(parse_data.quad_fn); if (parse_data.quad_fd < 0) { fs_error(LOG_ERR, "Cannot create tmp file “%s”", parse_data.quad_fn); return 1; } parse_data.muri = raptor_new_uri((unsigned char *) model_uri); parse_data.model = g_strdup(model_uri); parse_data.model_hash = fs_hash_uri(model_uri); parse_data.count_trip = 0; parse_data.count_err = 0; parse_data.last_count = 0; parse_data.has_o_index = has_o_index; /* store the model uri */ buffer_res(link, parse_data.segments, parse_data.model_hash, parse_data.model, FS_RID_NULL, parse_data.dryrun); parse_data.parser = raptor_new_parser_for_content(NULL, mimetype, NULL, 0, (unsigned char *) parse_data.model); if (!parse_data.parser) { return 1; } /* use us as a vector for an indirect attack? no thanks */ raptor_set_feature(parse_data.parser, RAPTOR_FEATURE_NO_NET, 0); raptor_set_fatal_error_handler(parse_data.parser, link, fatal_rdf_parser_error); raptor_set_error_handler(parse_data.parser, link, rdf_parser_error); raptor_set_statement_handler(parse_data.parser, &parse_data, store_stmt); raptor_set_graph_handler(parse_data.parser, &parse_data, graph_handler); raptor_start_parse(parse_data.parser, parse_data.muri); fs_hash_freshen(); /* blank nodes are unique per file */ return 0; }
static raptor_uri *rdf_parser_path_to_uri(raptor_world* world,char* path) { unsigned char *uri_string; raptor_uri *uri; uri_string = raptor_uri_filename_to_uri_string(path); uri=raptor_new_uri(world,uri_string); raptor_free_memory(uri_string); return uri; }
int main (int argc, char *argv[]) { const char *program = raptor_basename(argv[0]); raptor_world *world; const char *uri_string; raptor_www *www; const char *user_agent = "raptor_www_test/0.1"; raptor_uri *uri; void *string = NULL; size_t string_length = 0; if(argc > 1) uri_string = argv[1]; else uri_string = "http://librdf.org/"; world = raptor_new_world(); if(!world || raptor_world_open(world)) exit(1); uri = raptor_new_uri(world, (const unsigned char*)uri_string); if(!uri) { fprintf(stderr, "%s: Failed to create Raptor URI for %s\n", program, uri_string); exit(1); } www = raptor_new_www(world); raptor_www_set_content_type_handler(www, write_content_type, (void*)stderr); raptor_www_set_user_agent(www, user_agent); /* start retrieval (always a GET) */ if(raptor_www_fetch_to_string(www, uri, &string, &string_length, malloc)) { fprintf(stderr, "%s: WWW fetch failed\n", program); } else { #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 fprintf(stderr, "%s: HTTP response status %d\n", program, www->status_code); fprintf(stderr, "%s: Returned %d bytes of content\n", program, (int)string_length); #endif } if(string) free(string); raptor_free_www(www); raptor_free_uri(uri); raptor_free_world(world); return 0; }
static void rasqal_init_datatypes(void) { int i; raptor_xpfo_base_uri = raptor_new_uri((const unsigned char*)RASQAL_XPFO_BASE_URI); rasqal_sparql_op_namespace_uri = raptor_new_uri((const unsigned char*)RASQAL_SPARQL_OP_NAMESPACE_URI); for(i = 0; i< RASQAL_XSD_DATATYPES_SIZE; i++) { rasqal_xsd_datatypes[i].uri = raptor_new_uri_from_uri_local_name(raptor_xpfo_base_uri, (const unsigned char*)rasqal_xsd_datatypes[i].name); } for(i = 0; i< RASQAL_XSD_DATATYPE_FNS_SIZE; i++) { rasqal_xsd_datatype_fns[i].uri = raptor_new_uri_from_uri_local_name(rasqal_sparql_op_namespace_uri, rasqal_xsd_datatype_fns[i].name); } }
fs_metadata *fs_metadata_open(const char *kb) { fs_metadata *m = calloc(1, sizeof(fs_metadata)); gchar *fs_md_file_uri_format; fs_md_file_uri_format = g_strconcat("file://", fs_get_md_file_format(), NULL); m->size = 16; m->length = 0; m->entries = calloc(m->size, sizeof(struct m_entry)); m->uri = g_strdup_printf(fs_md_file_uri_format, kb); g_free(fs_md_file_uri_format); int fd; if ((fd = open(m->uri + 7, FS_O_NOATIME | O_CREAT, FS_FILE_MODE)) == -1) { fs_error(LOG_CRIT, "failed to touch metadata file %s: %s", m->uri, strerror(errno)); free(m); return NULL; } close(fd); m->rw = raptor_new_world(); if (!m->rw) { fs_error(LOG_CRIT, "failed to initialise raptor"); free(m); return NULL; } raptor_parser *rdf_parser = raptor_new_parser(m->rw, "turtle"); raptor_parser_set_statement_handler(rdf_parser, m, parse_stmt); char *uri = strdup(m->uri); raptor_uri *ruri = raptor_new_uri(m->rw, (unsigned char *) uri); raptor_uri *muri = raptor_new_uri(m->rw, (unsigned char *) uri); free(uri); if (raptor_parser_parse_uri(rdf_parser, ruri, muri)) { fs_error(LOG_ERR, "failed to parse metadata file “%s”", m->uri); return NULL; } raptor_free_parser(rdf_parser); raptor_free_uri(ruri); raptor_free_uri(muri); return m; }
/** * raptor_new_uri_from_rdf_ordinal: * @ordinal: integer rdf:_n * * Internal - convert an integer rdf:_n ordinal to the resource URI * * Return value: new URI object or NULL on failure **/ raptor_uri* raptor_new_uri_from_rdf_ordinal(int ordinal) { /* 55 = strlen(rdf namespace URI) + _ + 10-digit number + \0 */ unsigned char uri_string[55]; strncpy((char*)uri_string, (const char*)raptor_rdf_namespace_uri, raptor_rdf_namespace_uri_len); sprintf((char*)uri_string+raptor_rdf_namespace_uri_len, "_%d", ordinal); return raptor_new_uri(uri_string); }
int raptor_rss_common_init(raptor_world* world) { int i; raptor_uri *namespace_uri; if(world->rss_common_initialised++) return 0; world->rss_namespaces_info_uris = RAPTOR_CALLOC(raptor_uri**, RAPTOR_RSS_NAMESPACES_SIZE, sizeof(raptor_uri*)); if(!world->rss_namespaces_info_uris) return -1; for(i = 0; i < RAPTOR_RSS_NAMESPACES_SIZE;i++) { const char *uri_string = raptor_rss_namespaces_info[i].uri_string; if(uri_string) { world->rss_namespaces_info_uris[i] = raptor_new_uri(world, (const unsigned char*)uri_string); if(!world->rss_namespaces_info_uris[i]) return -1; } } world->rss_types_info_uris = RAPTOR_CALLOC(raptor_uri**, RAPTOR_RSS_COMMON_SIZE, sizeof(raptor_uri*)); if(!world->rss_types_info_uris) return -1; for(i = 0; i< RAPTOR_RSS_COMMON_SIZE; i++) { int n = raptor_rss_items_info[i].nspace; namespace_uri = world->rss_namespaces_info_uris[n]; if(namespace_uri) { world->rss_types_info_uris[i] = raptor_new_uri_from_uri_local_name(world, namespace_uri, (const unsigned char*)raptor_rss_items_info[i].name); if(!world->rss_types_info_uris[i]) return -1; } } world->rss_fields_info_uris = RAPTOR_CALLOC(raptor_uri**, RAPTOR_RSS_FIELDS_SIZE, sizeof(raptor_uri*)); if(!world->rss_fields_info_uris) return -1; for(i = 0; i< RAPTOR_RSS_FIELDS_SIZE; i++) { namespace_uri = world->rss_namespaces_info_uris[raptor_rss_fields_info[i].nspace]; if(namespace_uri) { world->rss_fields_info_uris[i] = raptor_new_uri_from_uri_local_name(world, namespace_uri, (const unsigned char*)raptor_rss_fields_info[i].name); if(!world->rss_fields_info_uris[i]) return -1; } } return 0; }
static void ser_emit_namespace(void* user_data, const char *prefix, size_t prefix_len, const char* uri, size_t uri_len) { raptor_serializer* serializer = (raptor_serializer*)user_data; raptor_uri *ns_uri = NULL; ns_uri = raptor_new_uri(rworld, (const unsigned char*)uri); raptor_serializer_set_namespace(serializer, ns_uri, (const unsigned char*)prefix); raptor_free_uri(ns_uri); }
int main (int argc, char *argv[]) { raptor_parser* rdf_parser; raptor_uri* uri; my_data* me; const char *program; int rc; program=argv[0]; if(argc != 2) { fprintf(stderr, "%s: USAGE [RDF-XML content URI]\n", program); exit(1); } raptor_init(); me=(my_data*)malloc(sizeof(my_data)); if(!me) { fprintf(stderr, "%s: Out of memory\n", program); exit(1); } me->stream=stderr; me->count=0; me->max=5; uri=raptor_new_uri((const unsigned char*)argv[1]); rdf_parser=raptor_new_parser("rdfxml"); me->parser=rdf_parser; raptor_set_statement_handler(rdf_parser, me, handle_statements); me->stopped=0; rc=raptor_parse_uri(rdf_parser, uri, NULL); fprintf(stderr, "%s: Parser returned status %d, stopped? %s\n", program, rc, (me->stopped ? "yes" : "no")); free(me); raptor_free_parser(rdf_parser); raptor_free_uri(uri); raptor_finish(); return 0; }
manifest_world* manifest_new_world(rasqal_world* world) { manifest_world* mw; raptor_world* raptor_world_ptr = rasqal_world_get_raptor(world); mw = (manifest_world*)calloc(sizeof(*mw), 1); if(!mw) return NULL; mw->world = world; mw->raptor_world_ptr = raptor_world_ptr; /* Create Namespace URIs, concept URIs and rasqal literal concepts */ mw->rdfs_namespace_uri = raptor_new_uri(raptor_world_ptr, raptor_rdf_schema_namespace_uri); mw->mf_namespace_uri = raptor_new_uri(raptor_world_ptr, (const unsigned char*)"http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#"); mw->t_namespace_uri = raptor_new_uri(raptor_world_ptr, (const unsigned char*)"http://ns.librdf.org/2009/test-manifest#"); mw->qt_namespace_uri = raptor_new_uri(raptor_world_ptr, (const unsigned char*)"http://www.w3.org/2001/sw/DataAccess/tests/test-query#"); mw->dawgt_namespace_uri = raptor_new_uri(raptor_world_ptr, (const unsigned char*)"http://www.w3.org/2001/sw/DataAccess/tests/test-dawg#"); mw->sd_namespace_uri = raptor_new_uri(raptor_world_ptr, (const unsigned char*)"http://www.w3.org/ns/sparql-service-description#"); mw->mf_Manifest_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->mf_namespace_uri, (const unsigned char*)"Manifest"); mw->mf_entries_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->mf_namespace_uri, (const unsigned char*)"entries"); mw->mf_name_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->mf_namespace_uri, (const unsigned char*)"name"); mw->mf_action_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->mf_namespace_uri, (const unsigned char*)"action"); mw->mf_result_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->mf_namespace_uri, (const unsigned char*)"result"); mw->mf_resultCardinality_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->mf_namespace_uri, (const unsigned char*)"resultCardinality"); mw->rdf_type_uri = raptor_new_uri_for_rdf_concept(raptor_world_ptr, (const unsigned char*)"type"); mw->rdf_first_uri = raptor_new_uri_for_rdf_concept(raptor_world_ptr, (const unsigned char*)"first"); mw->rdf_rest_uri = raptor_new_uri_for_rdf_concept(raptor_world_ptr, (const unsigned char*)"rest"); mw->rdf_nil_uri = raptor_new_uri_for_rdf_concept(raptor_world_ptr, (const unsigned char*)"nil"); mw->rdfs_comment_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->rdfs_namespace_uri, (const unsigned char*)"comment"); mw->t_path_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->t_namespace_uri, (const unsigned char*)"path"); mw->qt_data_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->qt_namespace_uri, (const unsigned char*)"data"); mw->qt_graphData_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->qt_namespace_uri, (const unsigned char*)"graphData"); mw->qt_query_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->qt_namespace_uri, (const unsigned char*)"query"); mw->dawgt_approval_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->dawgt_namespace_uri, (const unsigned char*)"approval"); mw->sd_entailmentRegime_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->sd_namespace_uri, (const unsigned char*)"entailmentRegime"); mw->mf_Manifest_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->mf_Manifest_uri)); mw->mf_entries_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->mf_entries_uri)); mw->mf_name_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->mf_name_uri)); mw->mf_action_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->mf_action_uri)); mw->mf_result_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->mf_result_uri)); mw->mf_resultCardinality_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->mf_resultCardinality_uri)); mw->rdf_type_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->rdf_type_uri)); mw->rdf_first_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->rdf_first_uri)); mw->rdf_rest_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->rdf_rest_uri)); mw->rdfs_comment_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->rdfs_comment_uri)); mw->t_path_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->t_path_uri)); mw->qt_data_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->qt_data_uri)); mw->qt_graphData_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->qt_graphData_uri)); mw->qt_query_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->qt_query_uri)); mw->dawgt_approval_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->dawgt_approval_uri)); mw->sd_entailmentRegime_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->sd_entailmentRegime_uri)); return mw; }
int main (int argc, char *argv[]) { const char *uri_string; raptor_www *www; const char *user_agent="raptor-www-test"; raptor_uri *uri; void *string=NULL; size_t string_length=0; if(argc>1) uri_string=argv[1]; else uri_string="http://librdf.org/"; raptor_uri_init(); raptor_www_init(); uri=raptor_new_uri((const unsigned char*)uri_string); if(!uri) { fprintf(stderr, "Failed to create Raptor URI for %s\n", uri_string); exit(1); } www=raptor_www_new(); raptor_www_set_content_type_handler(www, write_content_type, (void*)stderr); raptor_www_set_user_agent(www, user_agent); /* start retrieval (always a GET) */ if(raptor_www_fetch_to_string(www, uri, &string, &string_length, malloc)) { printf("WWW fetch failed\n"); } else { printf("HTTP response status %d\n", www->status_code); printf("Returned %d bytes of content\n", (int)string_length); } if(string) free(string); raptor_www_free(www); raptor_free_uri(uri); raptor_www_finish(); return 0; }
int rdfa_parse_start(rdfacontext* context) { /* create the buffers and expat parser */ int rval = RDFA_PARSE_SUCCESS; context->wb_allocated = sizeof(char) * READ_BUFFER_SIZE; /* +1 for NUL at end, to allow strstr() etc. to work * malloc - only the first char needs to be NUL */ context->working_buffer = (char*)malloc(context->wb_allocated + 1); *context->working_buffer = '\0'; context->done = 0; context->context_stack = rdfa_create_list(32); /* initialize the context stack */ rdfa_push_item(context->context_stack, context, RDFALIST_FLAG_CONTEXT); #ifdef LIBRDFA_IN_RAPTOR context->sax2 = raptor_new_sax2(context->world, context->locator, context); #else /* init libxml2 */ xmlInitParser(); #endif /* set up the context stack */ #ifdef LIBRDFA_IN_RAPTOR raptor_sax2_set_start_element_handler(context->sax2, raptor_rdfa_start_element); raptor_sax2_set_end_element_handler(context->sax2, raptor_rdfa_end_element); raptor_sax2_set_characters_handler(context->sax2, raptor_rdfa_character_data); raptor_sax2_set_namespace_handler(context->sax2, raptor_rdfa_namespace_handler); #endif rdfa_init_context(context); #ifdef LIBRDFA_IN_RAPTOR context->base_uri = raptor_new_uri(context->sax2->world, (const unsigned char*)context->base); raptor_sax2_parse_start(context->sax2, context->base_uri); #endif return rval; }
static QPair< const void*, raptor_identifier_type > convertNode(QMap< Node*, int >& nodeIDs, Node* node) { QPair< const void*, raptor_identifier_type > pair; if (node->attributes.exists(UtopiaSystem.uri)) { QString encoded = encodeUnicode(node->attributes.get(UtopiaSystem.uri).toString()); pair.first = raptor_new_uri((const unsigned char*) encoded.toAscii().data()); pair.second = RAPTOR_IDENTIFIER_TYPE_RESOURCE; } else { char nodeID[11]; sprintf(nodeID, "ID%08d", getNodeID(nodeIDs, node)); pair.first = (const unsigned char*) strdup(nodeID); pair.second = RAPTOR_IDENTIFIER_TYPE_ANONYMOUS; } return pair; }
/** * raptor_new_term_from_uri_string: * @world: raptor world * @uri_string: UTF-8 encoded URI string. * * Constructor - create a new URI statement term from a UTF-8 encoded Unicode string * * Return value: new term or NULL on failure */ raptor_term* raptor_new_term_from_uri_string(raptor_world* world, const unsigned char *uri_string) { raptor_term *t; raptor_uri* uri; RAPTOR_CHECK_CONSTRUCTOR_WORLD(world); uri = raptor_new_uri(world, uri_string); if(!uri) return NULL; t = raptor_new_term_from_uri(world, uri); raptor_free_uri(uri); return t; }
static void raptor_www_curl_update_status(raptor_www* www) { char* final_uri; if(www->failed) return; if(www->checked_status++) return; if(curl_easy_getinfo(www->curl_handle, CURLINFO_EFFECTIVE_URL, &final_uri) == CURLE_OK) { www->final_uri=raptor_new_uri((const unsigned char*)final_uri); if(www->final_uri_handler) www->final_uri_handler(www, www->final_uri_userdata, www->final_uri); } }