static int parse_one_blob(xmlNodePtr cur, xmlXPathContextPtr ctxt,
			  void *output)
{
  struct deltacloud_bucket_blob *thisblob = (struct deltacloud_bucket_blob *)output;
  struct deltacloud_bucket_blob_metadata *thisentry;
  xmlNodePtr meta_cur, entry_cur, oldnode;
  int ret = -1;

  oldnode = ctxt->node;

  memset(thisblob, 0, sizeof(struct deltacloud_bucket_blob));

  thisblob->href = getXPathString("string(./@href)", ctxt);
  thisblob->id = getXPathString("string(./@id)", ctxt);
  thisblob->bucket_id = getXPathString("string(./bucket)", ctxt);
  thisblob->content_length = getXPathString("string(./content_length)", ctxt);
  thisblob->content_type = getXPathString("string(./content_type)", ctxt);
  thisblob->last_modified = getXPathString("string(./last_modified)", ctxt);
  thisblob->content_href = getXPathString("string(./content/@href)", ctxt);

  meta_cur = cur->children;
  while (meta_cur != NULL) {
    if (meta_cur->type == XML_ELEMENT_NODE &&
	STREQ((const char *)meta_cur->name, "user_metadata")) {

      entry_cur = meta_cur->children;
      while (entry_cur != NULL) {
	if (entry_cur->type == XML_ELEMENT_NODE &&
	    STREQ((const char *)entry_cur->name, "entry")) {

	  ctxt->node = entry_cur;

	  thisentry = calloc(1, sizeof(struct deltacloud_bucket_blob_metadata));
	  if (thisentry == NULL) {
	    deltacloud_free_bucket_blob(thisblob);
	    oom_error();
	    goto cleanup;
	  }

	  thisentry->key = getXPathString("string(./@key)", ctxt);
	  thisentry->value = getXPathString("string(.)", ctxt);

	  if (thisentry->value != NULL) {
	    strip_trailing_whitespace(thisentry->value);
	    strip_leading_whitespace(thisentry->value);
	  }

	  /* add_to_list can't fail */
	  add_to_list(&thisblob->metadata,
		      struct deltacloud_bucket_blob_metadata, thisentry);
	}

	entry_cur = entry_cur->next;
      }
    }
Example #2
0
void
JsonWriterImpl::flush()
{
  assert(m_stack.size() == 1);
  std::stringstream out;
  if (false)
  {
    Json::StyledStreamWriter writer("  ");
    writer.write(out, m_stack.back());
    strip_trailing_whitespace(m_out, out);
  }
  else
  {
    Json::FastWriter writer;
    m_out << writer.write(m_stack.back());
  }
}