예제 #1
0
파일: import.c 프로젝트: nakao/4store
void graph_handler(void *user_data, raptor_uri *graph)
{
    g_free(parse_data.model);
    if (graph == NULL) {
        parse_data.model = g_strdup((char *) raptor_uri_as_string(parse_data.muri));
    } else {
        parse_data.model = g_strdup((char *) raptor_uri_as_string(graph));
    }

    parse_data.model_hash = fs_hash_uri(parse_data.model);
    buffer_res(parse_data.link, parse_data.segments, parse_data.model_hash, parse_data.model, FS_RID_NULL, parse_data.dryrun);
}
예제 #2
0
파일: metadata.c 프로젝트: garlik/4store
static void parse_stmt(void *user_data, raptor_statement *statement)
{
    fs_metadata *m = (fs_metadata *)user_data;

    char *pred = (char *)raptor_uri_as_string(statement->predicate->value.uri);
    char *obj = NULL;
    if (statement->object->type == RAPTOR_TERM_TYPE_LITERAL) {
        obj = (char *)statement->object->value.literal.string;
    } else {
        obj = (char *)raptor_uri_as_string(statement->object->value.uri);
    }

    fs_metadata_add(m, pred, obj);
}
/*
 * raptor_rdfxmla_emit_resource_uri:
 * @serializer: #raptor_serializer object
 * @element: XML Element
 * @uri: URI object
 * @depth: depth into tree
 * 
 * Emit a description of a resource using an XML Element
 * 
 * Return value: non-0 on failure
 **/
static int
raptor_rdfxmla_emit_resource_uri(raptor_serializer *serializer,
                                 raptor_xml_element *element,
                                 raptor_uri* uri,
                                 int depth) 
{
  raptor_rdfxmla_context* context = (raptor_rdfxmla_context*)serializer->context;
  raptor_xml_writer *xml_writer = context->xml_writer;
  raptor_qname **attrs;
  unsigned char *attr_name;
  unsigned char *attr_value;
  
  RAPTOR_DEBUG2("Emitting resource predicate URI %s\n",
                raptor_uri_as_string(uri));

  attrs = RAPTOR_CALLOC(raptor_qname**, 1, sizeof(raptor_qname*));
  if(!attrs)
    return 1;
    
  attr_name = (unsigned char *)"resource";

  if(RAPTOR_OPTIONS_GET_NUMERIC(serializer, RAPTOR_OPTION_RELATIVE_URIS))
    /* newly allocated string */
    attr_value = raptor_uri_to_relative_uri_string(serializer->base_uri, uri);
  else
    attr_value = raptor_uri_as_string(uri);

  attrs[0] = raptor_new_qname_from_namespace_local_name(serializer->world,
                                                        context->rdf_nspace,
                                                        attr_name, 
                                                        attr_value);
      
  if(RAPTOR_OPTIONS_GET_NUMERIC(serializer, RAPTOR_OPTION_RELATIVE_URIS))
    RAPTOR_FREE(char*, attr_value);

  if(!attrs[0]) {
    RAPTOR_FREE(qnamearray, attrs);
    return 1;
  }

  raptor_xml_element_set_attributes(element, attrs, 1);

  raptor_xml_writer_start_element(xml_writer, element);
  raptor_xml_writer_end_element(context->xml_writer, element);

  RAPTOR_DEBUG2("Emitted resource predicate URI %s\n",
                raptor_uri_as_string(uri));
  
  return 0;
}
예제 #4
0
파일: update.c 프로젝트: CloCkWeRX/4store
static int insert_rasqal_triple(struct update_context *uc, rasqal_triple *triple, int row)
{
    fs_rid quad_buf[1][4];
    fs_resource res;
    if (triple->origin) {
        fs_resource_from_rasqal_literal(uc, triple->origin, &res, row);
        quad_buf[0][0] = fs_hash_rasqal_literal(uc, triple->origin, row);
    } else if (uc->op->graph_uri) {
        res.lex = (char *)raptor_uri_as_string(uc->op->graph_uri);
        res.attr = FS_RID_NULL;
        quad_buf[0][0] =
            fs_hash_uri((char *)raptor_uri_as_string(uc->op->graph_uri));
    } else {
        quad_buf[0][0] = fs_c.default_graph;
        res.lex = FS_DEFAULT_GRAPH;
        res.attr = FS_RID_NULL;
    }

    if (quad_buf[0][0] == fs_c.system_config)
        fsp_reload_acl_system(uc->link);

    if (!FS_IS_URI(quad_buf[0][0])) {
        return 1;
    }
    quad_buf[0][1] = fs_hash_rasqal_literal(uc, triple->subject, row);
    if (FS_IS_LITERAL(quad_buf[0][1])) {
        return 1;
    }
    quad_buf[0][2] = fs_hash_rasqal_literal(uc, triple->predicate, row);
    if (!FS_IS_URI(quad_buf[0][2])) {
        return 1;
    }
    quad_buf[0][3] = fs_hash_rasqal_literal(uc, triple->object, row);
    res.rid = quad_buf[0][0];
    if (res.lex) fsp_res_import(uc->link, FS_RID_SEGMENT(quad_buf[0][0], uc->segments), 1, &res);
    res.rid = quad_buf[0][1];
    fs_resource_from_rasqal_literal(uc, triple->subject, &res, 0);
    if (res.lex) fsp_res_import(uc->link, FS_RID_SEGMENT(quad_buf[0][1], uc->segments), 1, &res);
    res.rid = quad_buf[0][2];
    fs_resource_from_rasqal_literal(uc, triple->predicate, &res, 0);
    if (res.lex) fsp_res_import(uc->link, FS_RID_SEGMENT(quad_buf[0][2], uc->segments), 1, &res);
    res.rid = quad_buf[0][3];
    fs_resource_from_rasqal_literal(uc, triple->object, &res, 0);
    if (res.lex) fsp_res_import(uc->link, FS_RID_SEGMENT(quad_buf[0][3], uc->segments), 1, &res);
    fsp_quad_import(uc->link, FS_RID_SEGMENT(quad_buf[0][1], uc->segments), FS_BIND_BY_SUBJECT, 1, quad_buf);
//printf("I %016llx %016llx %016llx %016llx\n", quad_buf[0][0], quad_buf[0][1], quad_buf[0][2], quad_buf[0][3]);

    return 0;
}
예제 #5
0
static int
raptor_librdfa_parse_start(raptor_parser* rdf_parser) 
{
  raptor_locator *locator=&rdf_parser->locator;
  raptor_librdfa_parser_context *librdfa_parser=(raptor_librdfa_parser_context*)rdf_parser->context;
  int rc;
  char* base_uri_string=NULL;
  
  locator->line=1;
  locator->column=0;
  locator->byte=0;

  if(rdf_parser->base_uri)
    base_uri_string=(char*)raptor_uri_as_string(rdf_parser->base_uri);

  if(librdfa_parser->context)
    rdfa_free_context(librdfa_parser->context);
  librdfa_parser->context=rdfa_create_context(base_uri_string);
  if(!librdfa_parser->context)
    return 1;

  librdfa_parser->context->namespace_handler=raptor_librdfa_sax2_new_namespace_handler;
  librdfa_parser->context->namespace_handler_user_data=rdf_parser;
  librdfa_parser->context->error_handlers=&rdf_parser->error_handlers;

  librdfa_parser->context->callback_data=rdf_parser;
  rdfa_set_triple_handler(librdfa_parser->context, 
                          raptor_librdfa_generate_statement);

  rc = rdfa_parse_start(librdfa_parser->context);
  if(rc != RDFA_PARSE_SUCCESS)
    return 1;
  
  return 0;
}
예제 #6
0
/**
 * 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;
}
예제 #7
0
파일: update.c 프로젝트: 66laps/4store
static int delete_rasqal_triple(struct update_context *ct, fs_rid_vector *vec[], rasqal_triple *triple, int row)
{
    fs_rid m, s, p, o;

    if (triple->origin) {
        m = fs_hash_rasqal_literal(ct, triple->origin, row);
        if (m == FS_RID_NULL) return 1;
    } else if (ct->op->graph_uri) {
        m = fs_hash_uri((char *)raptor_uri_as_string(ct->op->graph_uri));
    } else {
        /* m can be wildcard in the absence of GRAPH, WITH etc. */
        m = FS_RID_NULL;
    }
    s = fs_hash_rasqal_literal(ct, triple->subject, row);
    if (s == FS_RID_NULL) return 1;
    p = fs_hash_rasqal_literal(ct, triple->predicate, row);
    if (p == FS_RID_NULL) return 1;
    o = fs_hash_rasqal_literal(ct, triple->object, row);
    if (o == FS_RID_NULL) return 1;

    /* as long as s, p, and o are bound, we can add this quad */
    fs_rid_vector_append(vec[0], m);
    fs_rid_vector_append(vec[1], s);
    fs_rid_vector_append(vec[2], p);
    fs_rid_vector_append(vec[3], o);

    if (fs_rid_vector_length(vec[0]) > 999) {
        fsp_delete_quads_all(ct->link, vec);
        for (int s=0; s<4; s++) {
            fs_rid_vector_truncate(vec[s], 0);
        }
    }

    return 0;
}
예제 #8
0
/**
 * 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;
}
예제 #9
0
static void
raptor_dot_serializer_write_uri(raptor_serializer* serializer,
				raptor_uri* uri)
{
  raptor_dot_context* context = (raptor_dot_context*)serializer->context;
  unsigned char* full = raptor_uri_as_string(uri);
  int i;

  for( i = 0 ; i < raptor_sequence_size(context->namespaces) ; i++ ) {
    raptor_namespace* ns =
      (raptor_namespace*)raptor_sequence_get_at(context->namespaces, i);
    const unsigned char* ns_uri_string;
    size_t ns_uri_string_len;
    ns_uri_string=raptor_uri_as_counted_string(ns->uri, &ns_uri_string_len);

    if(!strncmp((char*)full, (char*)ns_uri_string, ns_uri_string_len) ) {
      const unsigned char* prefix = raptor_namespace_get_prefix(ns);
      
      if(prefix) {	
        raptor_iostream_write_string(serializer->iostream, prefix);
        raptor_iostream_write_byte(serializer->iostream, ':');
      }

      raptor_iostream_write_string(serializer->iostream,
                                   full + ns_uri_string_len);

      return;
    }
  }

  raptor_iostream_write_string(serializer->iostream, full);
}
예제 #10
0
파일: rdf_uri.c 프로젝트: Distrotech/librdf
/**
 * librdf_uri_as_string:
 * @uri: #librdf_uri object
 *
 * Get a pointer to the string representation of the URI.
 * 
 * Returns a shared pointer to the URI string representation. 
 * Note: does not allocate a new string so the caller must not free it.
 * 
 * Return value: string representation of URI
 **/
unsigned char*
librdf_uri_as_string (librdf_uri *uri) 
{
  LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(uri, librdf_uri, NULL);

  return raptor_uri_as_string(uri);
}
예제 #11
0
파일: update.c 프로젝트: CloCkWeRX/4store
static char *graph_arg(raptor_uri *u)
{
    if (!u) {
        return NULL;
    }

    return (char *)raptor_uri_as_string(u);
}
예제 #12
0
파일: rdf_uri.c 프로젝트: njh/librdf
/**
 * librdf_uri_as_string:
 * @uri: #librdf_uri object
 *
 * Get a pointer to the string representation of the URI.
 * 
 * Returns a shared pointer to the URI string representation. 
 * Note: does not allocate a new string so the caller must not free it.
 * 
 * Return value: string representation of URI
 **/
unsigned char*
librdf_uri_as_string (librdf_uri *uri) 
{
  LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(uri, librdf_uri, NULL);
#ifdef LIBRDF_USE_RAPTOR_URI
  return raptor_uri_as_string(uri);
#else
  return uri->string;
#endif
}
예제 #13
0
파일: optimiser.c 프로젝트: jen140/4store
/* detects the dreaded the:type predicate */
int fs_opt_literal_is_rdf_type(rasqal_literal *l)
{
    if (!l) return 0;

    if (l->type == RASQAL_LITERAL_URI) {
        if (!strcmp((char *)raptor_uri_as_string(l->value.uri), RDF_TYPE)) {
            return 1;
        }
    }

    return 0;
}
/*
 * raptor_rdfxmla_emit_literal:
 * @serializer: #raptor_serializer object
 * @element: XML Element
 * @node: literal node
 * @depth: depth into tree
 * 
 * Emit a description of a literal using an XML Element
 * 
 * Return value: non-0 on failure
 **/
static int
raptor_rdfxmla_emit_literal(raptor_serializer *serializer,
                            raptor_xml_element *element,
                            raptor_abbrev_node* node,
                            int depth)
{
  raptor_rdfxmla_context* context = (raptor_rdfxmla_context*)serializer->context;
  raptor_xml_writer *xml_writer = context->xml_writer;
  raptor_qname **attrs;
  int attrs_count;
  
  RAPTOR_DEBUG_ABBREV_NODE("Emitting literal node", node);

  if(node->term->type != RAPTOR_TERM_TYPE_LITERAL)
    return 1;
  
  if(node->term->value.literal.language || node->term->value.literal.datatype) {
          
    attrs_count = 0;
    attrs = RAPTOR_CALLOC(raptor_qname**, 2, sizeof(raptor_qname*));
    if(!attrs)
      return 1;

    if(node->term->value.literal.language) {
      attrs[attrs_count] = raptor_new_qname(context->nstack,
                                            (unsigned char*)"xml:lang",
                                            node->term->value.literal.language);
      if(!attrs[attrs_count])
        goto attrs_oom;
      attrs_count++;
    }

    if(node->term->value.literal.datatype) {
      unsigned char *datatype_value;
      datatype_value = raptor_uri_as_string(node->term->value.literal.datatype);
      attrs[attrs_count] = raptor_new_qname_from_namespace_local_name(serializer->world,
                                                                      context->rdf_nspace,
                                                                      (const unsigned char*)"datatype",
                                                                      datatype_value);
      if(!attrs[attrs_count])
        goto attrs_oom;
      attrs_count++;

      /* SJS Note: raptor_default_uri_as_string simply returns a
       * pointer to the string. Hope this is also true of alternate
       * uri implementations. */
      /* RAPTOR_FREE(char*, datatype_value); */

    }

    raptor_xml_element_set_attributes(element, attrs, attrs_count);

  }
예제 #15
0
파일: update.c 프로젝트: CloCkWeRX/4store
void fs_resource_from_rasqal_literal(struct update_context *uctxt, rasqal_literal *l, fs_resource *res, int row)
{
    if (!l) {
        res->lex = "(null)";
        res->attr = FS_RID_NULL;

        return;
    }
    rasqal_literal_type type = l->type;
    if (type == RASQAL_LITERAL_VARIABLE) {
        /* right now you can't introduce new literals in INSERT, so it doesn't
         * matter */
        res->lex = NULL;
        res->attr = FS_RID_GONE;
    } else if (type == RASQAL_LITERAL_URI) {
	res->lex = (char *)raptor_uri_as_string(l->value.uri);
        res->attr = FS_RID_NULL;
    } else {
        res->lex = (char *)l->string;
        res->attr = 0;
        fs_resource ares;
        ares.lex = NULL;
        if (l->datatype) {
            res->attr = fs_hash_uri((char *)raptor_uri_as_string(l->datatype));
            ares.rid = res->attr;
            ares.lex = (char *)raptor_uri_as_string(l->datatype);
            ares.attr = FS_RID_NULL;
        } else if (l->language) {
            res->attr = fs_hash_literal(l->language, 0);
            ares.rid = res->attr;
            ares.lex = (char *)l->language;
            ares.attr = 0;
        }
        /* insert attribute resource if there is one */
        if (ares.lex) {
            fsp_res_import(uctxt->link, FS_RID_SEGMENT(ares.rid, uctxt->segments), 1, &ares);
        }
    }
}
예제 #16
0
int
raptor_rss_item_set_uri(raptor_rss_item *item, raptor_uri* uri)
{
  RAPTOR_DEBUG3("Set node %p to URI <%s>\n", item,
                raptor_uri_as_string(uri));
  
  item->uri = raptor_uri_copy(uri);
  if(!item->uri)
    return 1;
  
  item->term = raptor_new_term_from_uri(item->world, item->uri);
  return 0;
}
예제 #17
0
static int
raptor_rss_parse_chunk(raptor_parser* rdf_parser, 
                       const unsigned char *s, size_t len,
                       int is_end)
{
  raptor_rss_parser_context* rss_parser=(raptor_rss_parser_context*)rdf_parser->context;
  int ret;
  
  if(!rss_parser->reader) {
    unsigned char *uri=raptor_uri_as_string(rdf_parser->base_uri);

    rss_parser->input=xmlParserInputBufferCreateMem((const char*)s, len,
                                                    XML_CHAR_ENCODING_NONE);
    rss_parser->reader=xmlNewTextReader(rss_parser->input, (const char*)uri);
    
    xmlTextReaderSetErrorHandler(rss_parser->reader,
                                 raptor_rss_error_handler, 
                                 rdf_parser);
  } else if(s && len)
    xmlParserInputBufferPush(rss_parser->input, len, (const char*)s);

  if(!is_end)
    return 0;
  
  ret = xmlTextReaderRead(rss_parser->reader);
  while (ret == 1) {
    if(rdf_parser->failed)
      break;
    
    raptor_rss_parser_processNode(rdf_parser);
    ret = xmlTextReaderRead(rss_parser->reader);
  }

  xmlFreeTextReader(rss_parser->reader);
  rss_parser->reader=NULL;
  
  xmlFreeParserInputBuffer(rss_parser->input);
  rss_parser->input=NULL;

  if(rdf_parser->failed)
    return 1;

  /* turn strings into URIs, move things around if needed */
  raptor_rss_insert_identifiers(rdf_parser);
  
  /* generate the triples */
  raptor_rss_emit(rdf_parser);

  return (ret != 0);
}
예제 #18
0
int
raptor_www_curl_fetch(raptor_www *www) 
{
  struct curl_slist *slist=NULL;
    
  if(www->proxy)
    curl_easy_setopt(www->curl_handle, CURLOPT_PROXY, www->proxy);

  if(www->user_agent)
    curl_easy_setopt(www->curl_handle, CURLOPT_USERAGENT, www->user_agent);

  if(www->http_accept)
    slist=curl_slist_append(slist, (const char*)www->http_accept);

  /* ALWAYS disable curl default "Pragma: no-cache" */
  slist=curl_slist_append(slist, "Pragma:");
  if(www->cache_control)
    slist=curl_slist_append(slist, (const char*)www->cache_control);

  if(slist)
    curl_easy_setopt(www->curl_handle, CURLOPT_HTTPHEADER, slist);

  /* specify URL to get */
  curl_easy_setopt(www->curl_handle, CURLOPT_URL, 
                   raptor_uri_as_string(www->uri));

  if(curl_easy_perform(www->curl_handle)) {
    /* failed */
    www->failed=1;
    raptor_www_error(www, "Resolving URI failed: %s", www->error_buffer);
  } else {
    long lstatus;

#ifndef CURLINFO_RESPONSE_CODE
#define CURLINFO_RESPONSE_CODE CURLINFO_HTTP_CODE
#endif

    /* Requires pointer to a long */
    if(curl_easy_getinfo(www->curl_handle, CURLINFO_RESPONSE_CODE, &lstatus) == CURLE_OK)
      www->status_code=lstatus;

  }

  if(slist)
    curl_slist_free_all(slist);
  
  return www->failed;
}
예제 #19
0
// static
void CRDFParser::NameSpaceHandler(void * pGraph, raptor_namespace * pNameSpace)
{
  const unsigned char * pURI =
    raptor_uri_as_string(raptor_namespace_get_uri(pNameSpace));
  std::string URI("");

  if (pURI) URI = (const char *) pURI;

  const unsigned char * pPrefix =
    raptor_namespace_get_prefix(pNameSpace);
  std::string Prefix("");

  if (pPrefix) Prefix = (const char *) pPrefix;

  static_cast<CRDFGraph *>(pGraph)->addNameSpace(Prefix, URI);
}
예제 #20
0
파일: rdfa.c 프로젝트: Distrotech/raptor
static void raptor_rdfa_end_element(void *user_data,
                                    raptor_xml_element* xml_element)
{
  raptor_qname* qname = raptor_xml_element_get_name(xml_element);
  unsigned char* localname = raptor_qname_to_counted_name(qname, NULL);
  const raptor_namespace* qname_ns = raptor_qname_get_namespace(qname);

  if(qname_ns)
    end_element(user_data, (const char*)localname,
                (const char*)qname_ns->prefix,
                (const xmlChar*)raptor_uri_as_string(qname_ns->uri));
  else
    end_element(user_data, (const char*)localname, NULL, NULL);

  raptor_free_memory(localname);
}
예제 #21
0
static rasqal_query_results_format_factory*
rasqal_get_query_results_formatter_factory(rasqal_world* world,
                                           const char *name, raptor_uri* uri,
                                           const char *mime_type,
                                           int flags)
{
  int i;
  rasqal_query_results_format_factory* factory = NULL;
  
  for(i = 0; 1; i++) {
    int factory_flags = 0;
    
    factory = (rasqal_query_results_format_factory*)raptor_sequence_get_at(world->query_results_formats,
                                                                         i);
    if(!factory)
      break;

    if(factory->reader)
      factory_flags |= RASQAL_QUERY_RESULTS_FORMAT_FLAG_READER;
    if(factory->writer)
      factory_flags |= RASQAL_QUERY_RESULTS_FORMAT_FLAG_WRITER;

    /* Flags must match */
    if(flags && factory_flags != flags)
      continue;

    if(!name && !uri)
      /* the default is the first registered format */
      break;
    
    if(name && factory->name &&
       !strcmp(factory->name, (const char*)name))
      return factory;


    if(uri && factory->uri_string &&
       !strcmp((const char*)raptor_uri_as_string(uri),
               (const char*)factory->uri_string))
      break;

    if(mime_type && factory->mime_type &&
       !strcmp(factory->mime_type, (const char*)mime_type))
      return factory;
  }
  
  return factory;
}
예제 #22
0
static int
raptor_librdfa_parse_start(raptor_parser* rdf_parser) 
{
  raptor_locator *locator = &rdf_parser->locator;
  raptor_librdfa_parser_context *librdfa_parser;
  int rc;
  char* base_uri_string = NULL;
  
  librdfa_parser = (raptor_librdfa_parser_context*)rdf_parser->context;

  locator->line = -1;
  locator->column = -1;
  locator->byte = 0;

  if(rdf_parser->base_uri)
    base_uri_string = (char*)raptor_uri_as_string(rdf_parser->base_uri);
  else
    /* base URI is required for rdfa - checked in rdfa_create_context() */
    return 1;

  if(librdfa_parser->context)
    rdfa_free_context(librdfa_parser->context);
  librdfa_parser->context = rdfa_create_context(base_uri_string);
  if(!librdfa_parser->context)
    return 1;

  librdfa_parser->context->namespace_handler = raptor_librdfa_sax2_new_namespace_handler;
  librdfa_parser->context->namespace_handler_user_data = rdf_parser;
  librdfa_parser->context->world = rdf_parser->world;
  librdfa_parser->context->locator = &rdf_parser->locator;
  
  librdfa_parser->context->callback_data = rdf_parser;
  /* returns triples */
  rdfa_set_default_graph_triple_handler(librdfa_parser->context, 
                                        raptor_librdfa_generate_statement);

  /* returns RDFa Processing Graph error triples - not used by raptor */
  rdfa_set_processor_graph_triple_handler(librdfa_parser->context, NULL);

  librdfa_parser->context->raptor_rdfa_version = librdfa_parser->rdfa_version;

  rc = rdfa_parse_start(librdfa_parser->context);
  if(rc != RDFA_PARSE_SUCCESS)
    return 1;
  
  return 0;
}
예제 #23
0
파일: rdf_term.c 프로젝트: herc/librdf
/**
 * librdf_node_get_li_ordinal:
 * @node: the node object
 *
 * Get the node li object ordinal value.
 *
 * Return value: the li ordinal value or < 1 on failure
 **/
int
librdf_node_get_li_ordinal(librdf_node *node)
{
  unsigned char *uri_string;

  LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(node, librdf_node, 0);

  if(node->type != RAPTOR_TERM_TYPE_URI)
    return -1;

  uri_string = raptor_uri_as_string(node->value.uri); 
  if(strncmp((const char*)uri_string,
             (const char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#_", 44))
    return -1;
  
  return atoi((const char*)uri_string+44);
}
예제 #24
0
파일: raptor_www.c 프로젝트: nevali/raptor
/**
* raptor_www_fetch:
* @www: WWW object
* @uri: URI to read from
* 
* Start a WWW content retrieval for the given URI, returning data via the write_bytes handler.
* 
* Return value: non-0 on failure.
**/
int
raptor_www_fetch(raptor_www *www, raptor_uri *uri) 
{
  int status = 1;
  
  www->uri = raptor_new_uri_for_retrieval(uri);
  
  www->locator.uri = uri;
  www->locator.line= -1;
  www->locator.column= -1;

  if(www->uri_filter)
    if(www->uri_filter(www->uri_filter_user_data, uri))
      return status;
  
#ifdef RAPTOR_WWW_NONE
  status = raptor_www_file_fetch(www);
#else

  if(raptor_uri_uri_string_is_file_uri(raptor_uri_as_string(www->uri)))
    status = raptor_www_file_fetch(www);
  else {
#ifdef RAPTOR_WWW_LIBCURL
    status = raptor_www_curl_fetch(www);
#endif

#ifdef RAPTOR_WWW_LIBXML
    status = raptor_www_libxml_fetch(www);
#endif

#ifdef RAPTOR_WWW_LIBFETCH
    status = raptor_www_libfetch_fetch(www);
#endif
  }
  
#endif
  if(!status && www->status_code && www->status_code != 200){
    raptor_www_error(www, "Resolving URI failed with HTTP status %d",
                     www->status_code);
    status = 1;
  }

  www->failed = status;
  
  return www->failed;
}
예제 #25
0
파일: raptor_www.c 프로젝트: nevali/raptor
static int 
raptor_www_file_fetch(raptor_www* www) 
{
  char *filename;
  FILE *fh;
  unsigned char *uri_string = raptor_uri_as_string(www->uri);
#if defined(HAVE_UNISTD_H) && defined(HAVE_SYS_STAT_H)
  struct stat buf;
#endif
  
  www->status_code = 200;

  filename = raptor_uri_uri_string_to_filename(uri_string);
  if(!filename) {
    raptor_www_error(www, "Not a file: URI");
    return 1;
  }

#if defined(HAVE_UNISTD_H) && defined(HAVE_SYS_STAT_H)
  if(!stat(filename, &buf) && S_ISDIR(buf.st_mode)) {
    raptor_www_error(www, "Cannot read from a directory '%s'", filename);
    RAPTOR_FREE(cstring, filename);
    www->status_code = 404;
    return 1;
  }
#endif

  fh = fopen(filename, "rb");
  if(!fh) {
    raptor_www_error(www, "file '%s' open failed - %s",
                     filename, strerror(errno));
    RAPTOR_FREE(cstring, filename);
    www->status_code = (errno == EACCES) ? 403: 404;
    www->failed = 1;
    
    return www->failed;
  }

  raptor_www_file_handle_fetch(www, fh);
  fclose(fh);

  RAPTOR_FREE(cstring, filename);
  
  return www->failed;
}
예제 #26
0
int
raptor_www_libxml_fetch(raptor_www *www) 
{
  if(www->proxy)
    xmlNanoHTTPScanProxy(www->proxy);

  www->ctxt=xmlNanoHTTPOpen((const char*)raptor_uri_as_string(www->uri), &www->type);
  if(!www->ctxt)
    return 1;
  
  if(www->type) {
    if(www->content_type) {
      www->content_type(www, www->content_type_userdata, www->type);
      if(www->failed) {
        xmlNanoHTTPClose(www->ctxt);
        return 1;
      }
    }
  }

  www->status_code=xmlNanoHTTPReturnCode(www->ctxt);
  
  while(1) {
    int len=xmlNanoHTTPRead(www->ctxt, www->buffer, RAPTOR_WWW_BUFFER_SIZE);
    if(len<0)
      break;
    
    www->total_bytes += len;

    if(www->write_bytes)
      www->write_bytes(www, www->write_bytes_userdata, www->buffer, len, 1);
    
    if(len < RAPTOR_WWW_BUFFER_SIZE || www->failed)
      break;
  }
  
  xmlNanoHTTPClose(www->ctxt);

  return www->failed;
}
예제 #27
0
int
raptor_www_libfetch_fetch(raptor_www *www) 
{
  FILE *stream;

  if(www->proxy) {
    setenv("HTTP_PROXY", www->proxy, 0);
    setenv("FTP_PROXY", www->proxy, 0);
  }

  if(www->user_agent)
    setenv("HTTP_USER_AGENT", www->user_agent, 0);

  stream = fetchXGetURL((const char*)raptor_uri_as_string(www->uri), NULL, NULL);
  if(!stream) {
    www->failed = 1;
    raptor_www_error(www, "%s", fetchLastErrString);
    return 1;
  }
  
  /* fetch does not give us access to this */
  www->status_code = 200;
  
  while(!feof(stream)) {
    size_t len = fread(www->buffer, 1, RAPTOR_WWW_BUFFER_SIZE, stream);
    
    www->total_bytes += len;

    if(www->write_bytes)
      www->write_bytes(www, www->write_bytes_userdata, www->buffer, len, 1);
    
    if(len < RAPTOR_WWW_BUFFER_SIZE)
      break;
  }
  fclose(stream);
  
  return www->failed;
}
예제 #28
0
/**
 * rasqal_data_graph_print:
 * @dg: #rasqal_data_graph object
 * @fh: the FILE* handle to print to
 *
 * Print a Rasqal data graph in a debug format.
 * 
 * The print debug format may change in any release.
 *
 * Return value: non-0 on failure
 **/
int
rasqal_data_graph_print(rasqal_data_graph* dg, FILE* fh)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(dg, rasqal_data_graph, 1);
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(fh, FILE*, 1);

  if(dg->iostr) {
    if(dg->name_uri)
      fprintf(fh, "data graph(from iostream, named as %s, flags %d", 
              raptor_uri_as_string(dg->name_uri), dg->flags);
    else
      fprintf(fh, "data graph(from iostream, %d", dg->flags);
  } else {
    /* dg->uri must exist */
    if(dg->name_uri)
      fprintf(fh, "data graph(from uri %s, named as %s, flags %d", 
              raptor_uri_as_string(dg->uri),
              raptor_uri_as_string(dg->name_uri),
              dg->flags);
    else
      fprintf(fh, "data graph(from uri %s, flags %d", 
              raptor_uri_as_string(dg->uri), dg->flags);
  }
  
  if(dg->format_type || dg->format_name || dg->format_uri) {
    fputs(" with format ", fh);
    if(dg->format_type)
      fprintf(fh, "type %s", dg->format_type);
    if(dg->format_name)
      fprintf(fh, "name %s", dg->format_name);
    if(dg->format_uri)
      fprintf(fh, "uri %s", raptor_uri_as_string(dg->format_uri));
    if(dg->base_uri)
      fprintf(fh, "base uri %s", raptor_uri_as_string(dg->base_uri));
  }
  fputc(')', fh);
  
  return 0;
}
예제 #29
0
static struct raptor_node_item build_term(raptor_term *triple)
{
	struct raptor_node_item n;
	n.type = triple->type;
	n.arg1 = NULL;
	n.arg2 = NULL;
	n.arg3 = NULL;

	switch(triple->type)
	{
	  	case RAPTOR_TERM_TYPE_UNKNOWN:
	  		//printf("BUILD: (UKNOWN)" );
	  		break ;

	  	case RAPTOR_TERM_TYPE_URI:
	  		//printf("uri( %s )", raptor_uri_as_string(triple->value.uri));

	  		if(triple->value.uri == NULL)
			{
	  			n.arg1 = malloc(1);
	  			strcpy(n.arg1, "");
	  		}
	  		else 
	  		{
	  			int size = strlen(raptor_uri_as_string(triple->value.uri));
	  			n.arg1 = malloc(sizeof(char) * (size + 1));
    			strncpy(n.arg1, raptor_uri_as_string(triple->value.uri), size + 1);
    			n.arg1[size] = 0;
	  		}

	  		break ;

	  	case RAPTOR_TERM_TYPE_LITERAL:
	  		//printf("literal( %s, %s, %s )", triple->value.literal.string, raptor_uri_as_string(triple->value.literal.datatype), triple->value.literal.language);

	  		// literal string
	  		if(triple->value.literal.string == NULL)
	  		{
	  			n.arg1 = malloc(1);
	  			strcpy(n.arg1, "");
	  		}
	  		else 
	  		{
	  			int size = strlen(triple->value.literal.string);
	  			n.arg1 = malloc(sizeof(char) * (size + 1));
    			strncpy(n.arg1, triple->value.literal.string, size + 1);
    			n.arg1[size] = 0;
	  		}

	  		// datatype string
	  		if(triple->value.literal.datatype == NULL)
	  		{
	  			n.arg2 = malloc(1);
	  			strcpy(n.arg2, "");
	  		}
	  		else 
	  		{
	  			int size = strlen(raptor_uri_as_string(triple->value.literal.datatype));
	  			n.arg2 = malloc(sizeof(char) * (size + 1));
    			strncpy(n.arg2, raptor_uri_as_string(triple->value.literal.datatype), size + 1);
    			n.arg2[size] = 0;
	  		}

	  		// language string
	  		if(triple->value.literal.language == NULL)
	  		{
	  			n.arg3 = malloc(1);
	  			strcpy(n.arg3, "");
	  		}
	  		else 
	  		{
	  			int size = strlen(triple->value.literal.language);
	  			n.arg3 = malloc(sizeof(char) * (size + 1));
    			strncpy(n.arg1, triple->value.literal.language, size + 1);
	  			n.arg3[size] = 0;
	  		}

	  		break ;

	  	case RAPTOR_TERM_TYPE_BLANK:
	  		 //printf("blank( %s )", triple->value.blank.string);

	  		if(triple->value.blank.string == NULL)
	  		{
	  			n.arg1 = malloc(1);
	  			strcpy(n.arg1, "");
	  		}
	  		else 
	  		{
	  			int size = strlen(triple->value.blank.string);
	  			n.arg1 = malloc(sizeof(char) * (size + 1));
    			strncpy(n.arg1, triple->value.blank.string, size + 1);
	  			n.arg1[size] = 0;
	  		}

	  		 break ;
	}

	return n;
}
예제 #30
0
/* end a serialize */
static int
raptor_dot_serializer_end(raptor_serializer* serializer)
{
  raptor_dot_context* context=(raptor_dot_context*)serializer->context;
  raptor_dot_serializer_node* node;
  int i;

  /* Print our nodes. */
  raptor_iostream_write_string(serializer->iostream,
                               (const unsigned char *)"\n\t// Resources\n");
  for( i = 0 ; i < raptor_sequence_size(context->resources) ; i++ ) {
    node = (raptor_dot_serializer_node*)raptor_sequence_get_at(context->resources, i);
    raptor_iostream_write_string(serializer->iostream,
                                 (const unsigned char *)"\t\"R");
    raptor_dot_serializer_write_node(serializer, node->value.resource.uri,
				     RAPTOR_IDENTIFIER_TYPE_RESOURCE, NULL, NULL);
    raptor_iostream_write_string(serializer->iostream,
                                 (const unsigned char *)"\" [ label=\"");
    raptor_dot_serializer_write_node(serializer, node->value.resource.uri,
				     RAPTOR_IDENTIFIER_TYPE_RESOURCE, NULL, NULL);
    raptor_iostream_write_string(serializer->iostream,
                                 (const unsigned char *)"\", shape=ellipse");
    raptor_dot_serializer_write_colors(serializer,
                                       RAPTOR_IDENTIFIER_TYPE_RESOURCE);
    raptor_iostream_write_string(serializer->iostream,
                                 (const unsigned char *)" ];\n");
    
  }
  raptor_free_sequence(context->resources);

  raptor_iostream_write_string(serializer->iostream,
                               (const unsigned char *)"\n\t// Anonymous nodes\n");
  for( i = 0 ; i < raptor_sequence_size(context->bnodes) ; i++ ) {
    node = (raptor_dot_serializer_node *)raptor_sequence_get_at(context->bnodes, i);
    raptor_iostream_write_string(serializer->iostream,
                                 (const unsigned char *)"\t\"B");
    raptor_dot_serializer_write_node(serializer, node->value.resource.uri,
				   RAPTOR_IDENTIFIER_TYPE_ANONYMOUS, NULL, NULL);
    raptor_iostream_write_string(serializer->iostream,
                                 (const unsigned char *)"\" [ label=\"");
    raptor_iostream_write_string(serializer->iostream,
                                 (const unsigned char *)"\", shape=circle");
    raptor_dot_serializer_write_colors(serializer,
                                       RAPTOR_IDENTIFIER_TYPE_ANONYMOUS);
    raptor_iostream_write_string(serializer->iostream,
                                 (const unsigned char *)" ];\n");
  }
  raptor_free_sequence(context->bnodes);

  raptor_iostream_write_string(serializer->iostream,
                               (const unsigned char *)"\n\t// Literals\n");
  for( i = 0 ; i < raptor_sequence_size(context->literals) ; i++ ) {
    node = (raptor_dot_serializer_node *)raptor_sequence_get_at(context->literals, i);
    raptor_iostream_write_string(serializer->iostream,
                                 (const unsigned char *)"\t\"L");
    raptor_dot_serializer_write_node(serializer, node->value.literal.string,
				     RAPTOR_IDENTIFIER_TYPE_LITERAL,
                                     node->value.literal.datatype,
				     node->value.literal.language);
    raptor_iostream_write_string(serializer->iostream,
                                 (const unsigned char *)"\" [ label=\"");
    raptor_dot_serializer_write_node(serializer, node->value.literal.string,
				     RAPTOR_IDENTIFIER_TYPE_LITERAL,
                                     node->value.literal.datatype,
				     node->value.literal.language);
    raptor_iostream_write_string(serializer->iostream,
                                 (const unsigned char *)"\", shape=record");
    raptor_dot_serializer_write_colors(serializer,
                                       RAPTOR_IDENTIFIER_TYPE_LITERAL);
    raptor_iostream_write_string(serializer->iostream,
                                 (const unsigned char *)" ];\n");
  }
  raptor_free_sequence(context->literals);

  raptor_iostream_write_string(serializer->iostream,
                               (const unsigned char *)"\n\tlabel=\"\\n\\nModel:\\n");
  if(serializer->base_uri)
    raptor_iostream_write_string(serializer->iostream,
                                 raptor_uri_as_string(serializer->base_uri));
  else
    raptor_iostream_write_string(serializer->iostream, "(Unknown)");

  if(raptor_sequence_size(context->namespaces)) {
    raptor_iostream_write_string(serializer->iostream,
                                 (const unsigned char *)"\\n\\nNamespaces:\\n");

    for( i = 0 ; i < raptor_sequence_size(context->namespaces) ; i++ ) {
      raptor_namespace* ns =
	(raptor_namespace*)raptor_sequence_get_at(context->namespaces, i);
      const unsigned char* prefix = raptor_namespace_get_prefix(ns);

      if(prefix) {
	raptor_iostream_write_string(serializer->iostream,
				     (const unsigned char *)ns->prefix);
	raptor_iostream_write_string(serializer->iostream,
				     (const unsigned char *)": ");
      }
      raptor_iostream_write_string(serializer->iostream,
				   raptor_uri_as_string(ns->uri));
      raptor_iostream_write_string(serializer->iostream,
				   (const unsigned char *)"\\n");
    }

    raptor_free_sequence(context->namespaces);
  }

  raptor_iostream_write_string(serializer->iostream,
                               (const unsigned char *)"\";\n");

  raptor_iostream_write_string(serializer->iostream,
                               (const unsigned char *) "}\n");

  return 0;
}