static int sd_add_dataset_description(librdf_model *sd_model, librdf_node *service_node) { librdf_node *dataset_node = NULL, *default_graph_node = NULL; int triple_count = librdf_storage_size(storage); dataset_node = librdf_new_node(world); if (!dataset_node) { redstore_error("Failed to create default dataset bnode - librdf_new_node returned NULL"); return 1; } librdf_model_add(sd_model, librdf_new_node_from_node(service_node), librdf_new_node_from_uri_local_name(world, sd_ns_uri, (const unsigned char *) "defaultDatasetDescription"), librdf_new_node_from_node(dataset_node) ); librdf_model_add(sd_model, librdf_new_node_from_node(dataset_node), librdf_new_node_from_node(LIBRDF_MS_type(world)), librdf_new_node_from_uri_local_name(world, sd_ns_uri, (const unsigned char *) "Dataset") ); default_graph_node = librdf_new_node(world); if (!default_graph_node) { redstore_error("Failed to create default graph bnode - librdf_new_node returned NULL"); return 1; } librdf_model_add(sd_model, librdf_new_node_from_node(dataset_node), librdf_new_node_from_uri_local_name(world, sd_ns_uri, (const unsigned char *) "defaultGraph"), librdf_new_node_from_node(default_graph_node) ); librdf_model_add(sd_model, librdf_new_node_from_node(default_graph_node), librdf_new_node_from_node(LIBRDF_MS_type(world)), librdf_new_node_from_uri_local_name(world, sd_ns_uri, (const unsigned char *) "Graph") ); if (triple_count>=0) { librdf_model_add(sd_model, librdf_new_node_from_node(default_graph_node), librdf_new_node_from_uri_local_name(world, void_ns_uri, (const unsigned char *) "triples"), new_node_from_integer(world, triple_count) ); } if (dataset_node) librdf_free_node(dataset_node); if (default_graph_node) librdf_free_node(default_graph_node); return 0; }
static librdf_storage_trees_graph* librdf_storage_trees_graph_new(librdf_storage* storage, librdf_node* context_node) { librdf_storage_trees_instance* context=(librdf_storage_trees_instance*)storage->instance; librdf_storage_trees_graph* graph=(librdf_storage_trees_graph*)LIBRDF_MALLOC( librdf_storage_trees_graph, sizeof(librdf_storage_trees_graph)); #ifdef RDF_STORAGE_TREES_WITH_CONTEXTS graph->context=(context_node ? librdf_new_node_from_node(context_node) : NULL); #endif /* Always create SPO index */ graph->spo_tree=librdf_new_avltree(librdf_statement_compare_spo, librdf_storage_trees_avl_free); if(!graph->spo_tree) { LIBRDF_FREE(librdf_storage_trees_graph, graph); return NULL; } if(context->index_sop) graph->sop_tree=librdf_new_avltree(librdf_statement_compare_sop, NULL); else graph->sop_tree=NULL; if(context->index_ops) graph->ops_tree=librdf_new_avltree(librdf_statement_compare_ops, NULL); else graph->ops_tree=NULL; if(context->index_pso) graph->pso_tree=librdf_new_avltree(librdf_statement_compare_pso, NULL); else graph->pso_tree=NULL; return graph; }
/** * librdf_new_statement_from_statement: * @statement: #librdf_statement to copy * * Copy constructor - create a new librdf_statement from an existing librdf_statement. * * Return value: a new #librdf_statement with copy or NULL on failure **/ librdf_statement* librdf_new_statement_from_statement(librdf_statement* statement) { librdf_statement* new_statement; LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(statement, librdf_statement, NULL); if(!statement) return NULL; new_statement = librdf_new_statement(statement->world); if(!new_statement) return NULL; if(statement->subject) { new_statement->subject=librdf_new_node_from_node(statement->subject); if(!new_statement->subject) { librdf_free_statement(new_statement); return NULL; } } if(statement->predicate) { new_statement->predicate=librdf_new_node_from_node(statement->predicate); if(!new_statement->predicate) { librdf_free_statement(new_statement); return NULL; } } if(statement->object) { new_statement->object=librdf_new_node_from_node(statement->object); if(!new_statement->object) { librdf_free_statement(new_statement); return NULL; } } return new_statement; }
static int sd_add_query_languages(librdf_model *sd_model, librdf_node *service_node) { int i,n; for(i=0; 1; i++) { const raptor_syntax_description* desc = librdf_query_language_get_description(world, i); librdf_node *lang_node = NULL; if (!desc) break; for (n = 0; desc->names[n]; n++) { if (strcmp(desc->names[n], "sparql10")==0) { lang_node = librdf_new_node_from_uri_local_name(world, sd_ns_uri, (unsigned char *) "SPARQL10Query"); break; } else if (strcmp(desc->names[n], "sparql11-query")==0) { lang_node = librdf_new_node_from_uri_local_name(world, sd_ns_uri, (unsigned char *) "SPARQL11Query"); break; } } if (lang_node) { librdf_model_add(sd_model, librdf_new_node_from_node(service_node), librdf_new_node_from_uri_local_name(world, sd_ns_uri, (const unsigned char *) "supportedLanguage"), librdf_new_node_from_node(lang_node) ); librdf_model_add(sd_model, librdf_new_node_from_node(lang_node), librdf_new_node_from_node(LIBRDF_S_comment(world)), librdf_new_node_from_literal(world, (const unsigned char *) desc->label, NULL, 0) ); if (desc->uri_strings) { for (n = 0; desc->uri_strings[n]; n++) { librdf_model_add(sd_model, librdf_new_node_from_node(lang_node), librdf_new_node_from_node(LIBRDF_S_seeAlso(world)), librdf_new_node_from_uri_string(world, (const unsigned char *) desc->uri_strings[n]) ); } } librdf_free_node(lang_node); } } return 0; }
static librdf_model * create_service_description(librdf_storage *sd_storage, const char * request_url) { librdf_model *sd_model = NULL; librdf_node *service_node = NULL; char *comment = NULL; sd_model = librdf_new_model(world, sd_storage, NULL); if (!sd_model) { redstore_error("Failed to create model for service description."); return NULL; } service_node = librdf_new_node(world); if (!service_node) { redstore_error("Failed to create service description bnode - librdf_new_node returned NULL"); librdf_free_model(sd_model); return NULL; } librdf_model_add(sd_model, librdf_new_node_from_node(service_node), librdf_new_node_from_node(LIBRDF_MS_type(world)), librdf_new_node_from_uri_local_name(world, sd_ns_uri, (unsigned char *) "Service") ); sd_add_format_descriptions(sd_model, service_node, librdf_parser_get_description, "inputFormat"); sd_add_format_descriptions(sd_model, service_node, librdf_serializer_get_description, "resultFormat"); sd_add_format_descriptions(sd_model, service_node, librdf_query_results_formats_get_description, "resultFormat"); sd_add_query_languages(sd_model, service_node); sd_add_dataset_description(sd_model, service_node); librdf_model_add(sd_model, librdf_new_node_from_node(service_node), librdf_new_node_from_node(LIBRDF_S_label(world)), librdf_new_node_from_literal(world, (unsigned char *) storage_name, NULL, 0) ); #define COMMENT_MAX_LEN (128) comment = malloc(COMMENT_MAX_LEN); snprintf(comment, COMMENT_MAX_LEN, "RedStore %s endpoint using the '%s' storage module.", PACKAGE_VERSION, storage_type); librdf_model_add(sd_model, librdf_new_node_from_node(service_node), librdf_new_node_from_node(LIBRDF_S_comment(world)), librdf_new_node_from_literal(world, (unsigned char *) comment, NULL, 0) ); free(comment); librdf_model_add(sd_model, librdf_new_node_from_node(service_node), librdf_new_node_from_uri_local_name(world, sd_ns_uri, (unsigned char *) "endpoint"), sd_get_endpoint_node(request_url) ); // Redland's default graph is the union of all other graphs librdf_model_add(sd_model, librdf_new_node_from_node(service_node), librdf_new_node_from_uri_local_name(world, sd_ns_uri, (unsigned char *) "feature"), librdf_new_node_from_uri_local_name(world, sd_ns_uri, (unsigned char *) "UnionDefaultGraph") ); librdf_free_node(service_node); return sd_model; }
static int sd_add_format_descriptions(librdf_model *sd_model, librdf_node *service_node, description_proc_t desc_proc, const char *type) { librdf_node *format_node = NULL; unsigned int i,n; for(i=0; 1; i++) { const raptor_syntax_description* desc = NULL; int uri_index = 0; desc = desc_proc(world, i); if (!desc) break; // Hack to remove the 'guess' format from the service description if (strcmp(desc->names[0], "guess") == 0) continue; // If the format has a format URI, use that, otherwise create a bnode if (desc->uri_strings && desc->uri_strings[0] && strncmp("http://www.w3.org/ns/formats/", desc->uri_strings[0], 29) == 0) { format_node = librdf_new_node_from_uri_string(world, (const unsigned char *) desc->uri_strings[0]); uri_index++; } else { format_node = librdf_new_node(world); } if (!format_node) { redstore_error("Failed to create new node for format."); return -1; } librdf_model_add(sd_model, librdf_new_node_from_node(format_node), librdf_new_node_from_node(LIBRDF_MS_type(world)), librdf_new_node_from_uri_local_name(world, format_ns_uri, (const unsigned char *) "Format") ); librdf_model_add(sd_model, librdf_new_node_from_node(service_node), librdf_new_node_from_uri_local_name(world, sd_ns_uri, (const unsigned char *) type), librdf_new_node_from_node(format_node) ); for (n = 0; desc->names[n]; n++) { librdf_model_add(sd_model, librdf_new_node_from_node(format_node), librdf_new_node_from_node(LIBRDF_S_label(world)), librdf_new_node_from_literal(world, (const unsigned char *) desc->names[n], NULL, 0) ); } if (desc->label) { librdf_model_add(sd_model, librdf_new_node_from_node(format_node), librdf_new_node_from_node(LIBRDF_S_comment(world)), librdf_new_node_from_literal(world, (const unsigned char *) desc->label, NULL, 0) ); } for (n = 0; n < desc->mime_types_count; n++) { const raptor_type_q mime_type = desc->mime_types[n]; librdf_model_add(sd_model, librdf_new_node_from_node(format_node), librdf_new_node_from_uri_local_name(world, format_ns_uri, (const unsigned char *) "media_type"), librdf_new_node_from_literal(world, (unsigned char *) mime_type.mime_type, NULL, 0) ); } if (desc->uri_strings) { int firstUri = uri_index; for (; desc->uri_strings[uri_index]; uri_index++) { const unsigned char *uri_string = (const unsigned char *) desc->uri_strings[uri_index]; if (firstUri == uri_index) { librdf_model_add(sd_model, librdf_new_node_from_node(format_node), librdf_new_node_from_node(LIBRDF_S_isDefinedBy(world)), librdf_new_node_from_uri_string(world, uri_string) ); } else { librdf_model_add(sd_model, librdf_new_node_from_node(format_node), librdf_new_node_from_node(LIBRDF_S_seeAlso(world)), librdf_new_node_from_uri_string(world, uri_string) ); } } } librdf_free_node(format_node); } return 0; }