Esempio n. 1
0
/**
 * librdf_init_concepts:
 * @world: redland world object
 *
 * INTERNAL - Initialise the concepts module.
 *
 **/
void
librdf_init_concepts(librdf_world *world)
{
    int i;

    /* Create the Unique URI objects */
    world->concept_ms_namespace_uri=librdf_new_uri(world, librdf_concept_ms_namespace);
    world->concept_schema_namespace_uri=librdf_new_uri(world, librdf_concept_schema_namespace);
    if(!world->concept_ms_namespace_uri || !world->concept_schema_namespace_uri)
        LIBRDF_FATAL1(world, LIBRDF_FROM_CONCEPTS, "Failed to create M&S or Schema URIs");

    /* Create arrays for the M&S and Schema resource nodes and uris */
    world->concept_uris=
        (librdf_uri**)LIBRDF_CALLOC(ptrarray, LIBRDF_CONCEPT_LAST+1, sizeof(librdf_uri*));
    world->concept_resources=
        (librdf_node**)LIBRDF_CALLOC(ptrarray, LIBRDF_CONCEPT_LAST+1, sizeof(librdf_node*));
    if(!world->concept_uris || !world->concept_resources)
        LIBRDF_FATAL1(world, LIBRDF_FROM_CONCEPTS, "Out of memory creating node/uri arrays");

    /* Create the M&S and Schema resource nodes */
    for (i=0; i<= LIBRDF_CONCEPT_LAST; i++) {
        librdf_uri* ns_uri=(i < LIBRDF_CONCEPT_FIRST_S_ID) ? world->concept_ms_namespace_uri :
                           world->concept_schema_namespace_uri;
        const unsigned char * token=(const unsigned char *)librdf_concept_tokens[i];

        world->concept_resources[i]=librdf_new_node_from_uri_local_name(world, ns_uri, token);
        if(!world->concept_resources[i])
            LIBRDF_FATAL1(world, LIBRDF_FROM_CONCEPTS, "Failed to create Node from URI\n");

        /* keep shared copy of URI from node */
        world->concept_uris[i]=librdf_node_get_uri(world->concept_resources[i]);
    }
}
Esempio n. 2
0
/**
 * librdf_storage_register_factory - Register a storage factory
 * @name: the storage factory name
 * @label: the storage factory label
 * @factory: pointer to function to call to register the factory
 * 
 **/
void
librdf_storage_register_factory(const char *name, const char *label,
				void (*factory) (librdf_storage_factory*)) 
{
  librdf_storage_factory *storage, *h;
  char *name_copy;
  char *label_copy;
  
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1
  LIBRDF_DEBUG2("Received registration for storage %s\n", name);
#endif
  
  storage=(librdf_storage_factory*)LIBRDF_CALLOC(librdf_storage_factory, 1,
                                                 sizeof(librdf_storage_factory));
  if(!storage)
    LIBRDF_FATAL1(world, "Out of memory");

  name_copy=(char*)LIBRDF_CALLOC(cstring, strlen(name)+1, 1);
  if(!name_copy) {
    LIBRDF_FREE(librdf_storage, storage);
    LIBRDF_FATAL1(world, "Out of memory");
  }
  strcpy(name_copy, name);
  storage->name=name_copy;
        
  for(h = storages; h; h = h->next ) {
    if(!strcmp(h->name, name_copy)) {
      LIBRDF_FREE(cstring, name_copy); 
      LIBRDF_FREE(librdf_storage, storage);
      LIBRDF_ERROR2(NULL, "storage %s already registered\n", h->name);
      return;
    }
  }
  
  label_copy=(char*)LIBRDF_CALLOC(cstring, strlen(label)+1, 1);
  if(!label_copy) {
    LIBRDF_FREE(librdf_storage, storage);
    LIBRDF_FATAL1(world, "Out of memory");
  }
  strcpy(label_copy, label);
  storage->label=label_copy;
        
  /* Call the storage registration function on the new object */
  (*factory)(storage);
  
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1
  LIBRDF_DEBUG3("%s has context size %d\n", name, storage->context_length);
#endif
  
  storage->next = storages;
  storages = storage;
}
Esempio n. 3
0
/**
 * librdf_init_raptor:
 * @world: librdf_world object
 * 
 * INTERNAL - Initialize the raptor library.
 * 
 * Initializes the raptor library unless a raptor instance is provided
 * externally with librdf_world_set_raptor() (and using raptor v2 APIs).
 * Sets raptor uri handlers to work with #librdf_uri objects.
 *
 * Return value: non-0 on failure
 **/
int
librdf_init_raptor(librdf_world* world)
{
  if(!world->raptor_world_ptr) {
    world->raptor_world_ptr = raptor_new_world();
    world->raptor_world_allocated_here = 1;

    if(world->raptor_world_ptr && world->raptor_init_handler) {
      world->raptor_init_handler(world->raptor_init_handler_user_data,
                                 world->raptor_world_ptr);
    }

    if(!world->raptor_world_ptr || raptor_world_open(world->raptor_world_ptr)) {
      LIBRDF_FATAL1(world, LIBRDF_FROM_PARSER, "failed to initialize raptor");
      return 1;
    }
  }

  /* New in-memory hash for mapping bnode IDs */
  world->bnode_hash = librdf_new_hash(world, NULL);
  if(!world->bnode_hash)
    return 1;


  /* set up log handler */
  raptor_world_set_log_handler(world->raptor_world_ptr, world,
                               librdf_raptor_log_handler);

  /* set up blank node identifier generation handler */
  raptor_world_set_generate_bnodeid_handler(world->raptor_world_ptr,
                                            world,
                                            librdf_raptor_generate_id_handler);

  return 0;
}
Esempio n. 4
0
/**
 * librdf_init_uri:
 * @world: redland world object
 *
 * INTERNAL - Initialise the uri module.
 *
 **/
void
librdf_init_uri(librdf_world *world)
{
  /* If no default given, create an in memory hash */
  if(!world->uris_hash) {
    world->uris_hash=librdf_new_hash(world, NULL);
    if(!world->uris_hash)
      LIBRDF_FATAL1(world, LIBRDF_FROM_URI, "Failed to create URI hash from factory");
    
    /* remember to free it later */
    world->uris_hash_allocated_here=1;

    if(librdf_hash_open(world->uris_hash, NULL, 0, 1, 1, NULL))
      LIBRDF_FATAL1(world, LIBRDF_FROM_URI, "Failed to open URI hash");
  }
}
Esempio n. 5
0
size_t
librdf_statement_decode(librdf_statement* statement, 
                        unsigned char *buffer, size_t length)
{
  /* FIXME - this should not just fail */
  LIBRDF_FATAL1(NULL, LIBRDF_FROM_STATEMENT,
                "librdf_statement_decode() cannot be used with Raptor V2");
  return 0;
}
Esempio n. 6
0
void
librdf_sign_free(void *ptr)
{
  int *p;

  if(!ptr)
    return;
  
  p = (int*)ptr;
  p--;

  if(*p != LIBRDF_SIGN_KEY)
    LIBRDF_FATAL1(NULL, LIBRDF_FROM_MEMORY, "memory signature wrong");

  free(p);
}
Esempio n. 7
0
void*
librdf_sign_realloc(void *ptr, size_t size)
{
  int *p;

  if(!ptr)
    return librdf_sign_malloc(size);
  
  p = (int*)ptr;
  p--;

  if(*p != LIBRDF_SIGN_KEY)
    LIBRDF_FATAL1(NULL, LIBRDF_FROM_MEMORY, "memory signature wrong\n");

  size += sizeof(int);
  
  p = (int*)realloc(p, size);
  *p++ = LIBRDF_SIGN_KEY;
  return p;
}
Esempio n. 8
0
/**
 * librdf_init_concepts - Initialise the concepts module.
 * @world: redland world object
 * 
 **/
void
librdf_init_concepts(librdf_world *world)
{
  int i;


  /* Create the Unique URI objects */
  librdf_concept_ms_namespace_uri=librdf_new_uri(world, librdf_concept_ms_namespace);
  librdf_concept_schema_namespace_uri=librdf_new_uri(world, librdf_concept_schema_namespace);

  /* Create the M&S and Schema resource nodes */
  for (i=0; i< LIBRDF_CONCEPT_LAST; i++) {
    librdf_uri* ns_uri=(i < LIBRDF_CONCEPT_FIRST_S_ID) ? librdf_concept_ms_namespace_uri :
      librdf_concept_schema_namespace_uri;
    const unsigned char * token=(const unsigned char *)librdf_concept_tokens[i];

    librdf_concept_resources[i]=librdf_new_node_from_uri_local_name(world, ns_uri, token);
    if(!librdf_concept_resources[i])
      LIBRDF_FATAL1(world, "Failed to create Node from URI\n");

    /* keep shared copy of URI from node */
    librdf_concept_uris[i]=librdf_node_get_uri(librdf_concept_resources[i]);
  }
}
Esempio n. 9
0
int
librdf_query_rasqal_constructor(librdf_world *world)
{
  unsigned int i;

  if(!world->rasqal_world_ptr) {
    world->rasqal_world_ptr=rasqal_new_world();
    world->rasqal_world_allocated_here = 1;

    if(!world->rasqal_world_ptr) {
      LIBRDF_FATAL1(world, LIBRDF_FROM_QUERY, "failed to initialize rasqal");
    }

    /* Make sure rasqal works with the same raptor instance as everyone else. */
    rasqal_world_set_raptor(world->rasqal_world_ptr, world->raptor_world_ptr);

    if(world->rasqal_world_ptr && world->rasqal_init_handler) {
      world->rasqal_init_handler(world->rasqal_init_handler_user_data,
                                 world->rasqal_world_ptr);
    }

    if(rasqal_world_open(world->rasqal_world_ptr)) {
      LIBRDF_FATAL1(world, LIBRDF_FROM_QUERY, "failed to initialize rasqal");
    }
  }


  rasqal_set_triples_source_factory(world->rasqal_world_ptr, rasqal_redland_register_triples_source_factory, world);

  /* enumerate from query language 1, so the default query language 0
   * is done last 
   */
  for(i = 1; 1; i++) {
    const raptor_syntax_description* desc = NULL;
    const char* uri_string = NULL;

    desc = rasqal_world_get_query_language_description(world->rasqal_world_ptr, i);
    if(!desc) {
      /* reached the end of the query languages, now register the default one */
      i = 0;

      desc = rasqal_world_get_query_language_description(world->rasqal_world_ptr, i);
      if(!desc) {
        LIBRDF_FATAL1(world, LIBRDF_FROM_QUERY, "failed to initialize rasqal");
      }
    }

    uri_string = desc->uri_strings_count ? desc->uri_strings[0] : NULL;

    librdf_query_register_factory(world, desc->names[0], (const unsigned char*)uri_string,
                                  &librdf_query_rasqal_register_factory);
    
    if(!i) /* registered default query, end */
      break;
  }


#if 0
  /* FIXME - this should be used but for now it is safe to assume
   * all query is done by Rasqal
   */

  /* enumerate query result formats */
  for(i=0; 1; i++) {
    const char *format_name=NULL;
    const char *format_label=NULL;
    const unsigned char *format_uri_string=NULL;
    const char *format_mime_type=NULL;

    if(rasqal_query_results_formats_enumerate_full(i, 
                                                   &format_name,
                                                   &format_label,
                                                   &format_uri_string, 
                                                   &format_mime_type))
      break;
    
    librdf_query_register_result_format(world, format_name, format_label,
                                        format_uri_string, format_mime_type,
                                        &librdf_query_rasqal_register_factory);
  }
#endif

  return 0;
}
Esempio n. 10
0
/**
 * librdf_serializer_register_factory:
 * @world: redland world object
 * @name: the name of the serializer
 * @label: the label of the serializer (optional)
 * @mime_type: MIME type of the syntax (optional)
 * @uri_string: URI of the syntax (optional)
 * @factory: function to be called to register the factor parameters
 *
 * Register a serializer factory .
 * 
 **/
REDLAND_EXTERN_C
void
librdf_serializer_register_factory(librdf_world *world,
                                   const char *name, const char *label,
                                   const char *mime_type,
                                   const unsigned char *uri_string,
                                   void (*factory) (librdf_serializer_factory*))
{
  librdf_serializer_factory *serializer;

  librdf_world_open(world);

#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1
  LIBRDF_DEBUG2("Received registration for serializer %s\n", name);
#endif

  if(!world->serializers) {
    world->serializers = raptor_new_sequence((raptor_data_free_handler)librdf_free_serializer_factory, NULL);

    if(!world->serializers)
      goto oom;
  }

  serializer=(librdf_serializer_factory*)LIBRDF_CALLOC(librdf_serializer_factory, 1,
                                                       sizeof(librdf_serializer_factory));
  if(!serializer)
    goto oom;

  serializer->name=(char*)LIBRDF_MALLOC(cstring, strlen(name)+1);
  if(!serializer->name)
    goto oom_tidy;
  strcpy(serializer->name, name);

  if(label) {
    serializer->label=(char*)LIBRDF_MALLOC(cstring, strlen(label)+1);
    if(!serializer->label)
      goto oom_tidy;
    strcpy(serializer->label, label);
  }

  /* register mime type if any */
  if(mime_type) {
    serializer->mime_type=(char*)LIBRDF_MALLOC(cstring, strlen(mime_type)+1);
    if(!serializer->mime_type)
      goto oom_tidy;
    strcpy(serializer->mime_type, mime_type);
  }

  /* register URI if any */
  if(uri_string) {
    serializer->type_uri=librdf_new_uri(world, uri_string);
    if(!serializer->type_uri)
      goto oom_tidy;
  }

  if(raptor_sequence_push(world->serializers, serializer)) 
    goto oom;

  /* Call the serializer registration function on the new object */
  (*factory)(serializer);

#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1
  LIBRDF_DEBUG3("%s has context size %d\n", name, serializer->context_length);
#endif

  return;

  oom_tidy:
  librdf_free_serializer_factory(serializer);
  oom:
  LIBRDF_FATAL1(world, LIBRDF_FROM_SERIALIZER, "Out of memory");
}