/** * rasqal_new_service: * @world: rasqal_world object * @service_uri: sparql protocol service URI * @query_string: query string (or NULL) * @data_graphs: sequence of #rasqal_data_graph graphs for service * * Constructor - create a new rasqal protocol service object. * * Create a structure to execute a sparql protocol service at * @service_uri running the query @query_string and returning * a sparql result set. * * All arguments are copied by the service object * * Return value: a new #rasqal_query object or NULL on failure */ rasqal_service* rasqal_new_service(rasqal_world* world, raptor_uri* service_uri, const char* query_string, raptor_sequence* data_graphs) { rasqal_service* svc; size_t len = 0; RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, NULL); RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(service_uri, raptor_uri, NULL); svc = (rasqal_service*)RASQAL_CALLOC(rasqal_service, 1, sizeof(*svc)); if(!svc) return NULL; svc->world = world; svc->service_uri = raptor_uri_copy(service_uri); if(query_string) { len = strlen(query_string); svc->query_string = RASQAL_MALLOC(cstring, len + 1); if(!svc->query_string) { rasqal_free_service(svc); return NULL; } memcpy(svc->query_string, query_string, len + 1); } svc->query_string_len = len; if(data_graphs) { int i; rasqal_data_graph* dg; #ifdef HAVE_RAPTOR2_API svc->data_graphs = raptor_new_sequence((raptor_data_free_handler)rasqal_free_data_graph, NULL); #else svc->data_graphs = raptor_new_sequence((raptor_sequence_free_handler*)rasqal_free_data_graph, NULL); #endif if(!svc->data_graphs) { rasqal_free_service(svc); return NULL; } for(i = 0; (dg = (rasqal_data_graph*)raptor_sequence_get_at(data_graphs, i)); i++) { raptor_sequence_push(svc->data_graphs, rasqal_new_data_graph_from_data_graph(dg)); } } return svc; }
/** * rasqal_new_service_rowsource: * @world: world object * @query: query object * @service_uri: service URI * @query_string: query to send to service * @data_graphs: sequence of data graphs (or NULL) * @rs_flags: service rowsource flags * * INTERNAL - create a new rowsource that takes rows from a service * * All arguments are copied. * * Return value: new rowsource or NULL on failure */ rasqal_rowsource* rasqal_new_service_rowsource(rasqal_world *world, rasqal_query* query, raptor_uri* service_uri, const unsigned char* query_string, raptor_sequence* data_graphs, unsigned int rs_flags) { rasqal_service_rowsource_context* con = NULL; rasqal_service* svc = NULL; int flags = 0; int silent = (rs_flags & RASQAL_ENGINE_BITFLAG_SILENT); if(!world || !query_string) goto fail; svc = rasqal_new_service(query->world, service_uri, query_string, data_graphs); if(!svc) { if(!silent) goto fail; /* Silent errors so tidy up and return empty rowsource */ RASQAL_FREE(cstring, query_string); if(data_graphs) raptor_free_sequence(data_graphs); return rasqal_new_empty_rowsource(world, query); } con = RASQAL_CALLOC(rasqal_service_rowsource_context*, 1, sizeof(*con)); if(!con) goto fail; con->svc = svc; con->query = query; con->flags = rs_flags; return rasqal_new_rowsource_from_handler(world, query, con, &rasqal_service_rowsource_handler, query->vars_table, flags); fail: if(svc) rasqal_free_service(svc); if(con) RASQAL_FREE(rasqal_service_rowsource_context, con); if(query_string) RASQAL_FREE(cstring, query_string); if(data_graphs) raptor_free_sequence(data_graphs); return NULL; }
static int rasqal_service_rowsource_finish(rasqal_rowsource* rowsource, void *user_data) { rasqal_service_rowsource_context* con; con = (rasqal_service_rowsource_context*)user_data; if(con->svc) rasqal_free_service(con->svc); if(con->rowsource) rasqal_free_rowsource(con->rowsource); RASQAL_FREE(rasqal_service_rowsource_context, con); return 0; }
static rasqal_query_results* roqet_call_sparql_service(rasqal_world* world, raptor_uri* service_uri, const unsigned char* query_string, raptor_sequence* data_graphs, const char* format) { rasqal_service* svc; rasqal_query_results* results; svc = rasqal_new_service(world, service_uri, query_string, data_graphs); if(!svc) { fprintf(stderr, "%s: Failed to create service object\n", program); return NULL; } rasqal_service_set_format(svc, format); results = rasqal_service_execute(svc); rasqal_free_service(svc); return results; }