// FIXME: This code is taken from libexslt 1.1.11; should sync with newer versions.
static void exsltNodeSetFunction(xmlXPathParserContextPtr ctxt, int nargs)
{
    xmlChar *strval;
    xmlNodePtr retNode;
    xmlXPathObjectPtr ret;

    if (nargs != 1) {
        xmlXPathSetArityError(ctxt);
        return;
    }

    if (xmlXPathStackIsNodeSet(ctxt)) {
        xsltFunctionNodeSet(ctxt, nargs);
        return;
    }

    strval = xmlXPathPopString(ctxt);
    retNode = xmlNewDocText(NULL, strval);
    ret = xmlXPathNewValueTree(retNode);
    if (ret == NULL) {
        xsltGenericError(xsltGenericErrorContext,
                         "exsltNodeSetFunction: ret == NULL\n");
    } else {
        ret->type = XPATH_NODESET;
    }

    if (strval != NULL)
        xmlFree(strval);

    valuePush(ctxt, ret);
}
// FIXME: This code is taken from libexslt 1.1.11; should sync with newer
// versions.
static void exsltNodeSetFunction(xmlXPathParserContextPtr ctxt, int nargs)
{
    xmlChar* strval;
    xmlNodePtr retNode;
    xmlXPathObjectPtr ret;

    if (nargs != 1) {
        xmlXPathSetArityError(ctxt);
        return;
    }

    if (xmlXPathStackIsNodeSet(ctxt)) {
        xsltFunctionNodeSet(ctxt, nargs);
        return;
    }

    strval = xmlXPathPopString(ctxt);
    retNode = xmlNewDocText(0, strval);
    ret = xmlXPathNewValueTree(retNode);

    // FIXME: It might be helpful to push any errors from xmlXPathNewValueTree
    // up to the Javascript Console.
    if (ret)
        ret->type = XPATH_NODESET;

    if (strval)
        xmlFree(strval);

    valuePush(ctxt, ret);
}
Beispiel #3
0
// Text createTextNode(in DOMString data);
static void _createTextNode(Request& r, MethodParams& params) {
	xmlChar* data=as_xmlchar(r, params, 0, XML_DATA_MUST_BE_STRING);

	VXdoc& vdoc=GET_SELF(r, VXdoc);
	xmlDoc& xmldoc=vdoc.get_xmldoc();

	xmlNode *node=xmlNewDocText(&xmldoc, data);
	writeNode(r, vdoc, node);
}
Beispiel #4
0
static void
exsltNodeSetFunction (xmlXPathParserContextPtr ctxt, int nargs) {
    if (nargs != 1) {
	xmlXPathSetArityError(ctxt);
	return;
    }
    if (xmlXPathStackIsNodeSet (ctxt)) {
	xsltFunctionNodeSet (ctxt, nargs);
	return;
    } else {
	xmlDocPtr fragment;
	xsltTransformContextPtr tctxt = xsltXPathGetTransformContext(ctxt);
	xmlNodePtr txt;
	xmlChar *strval;
	xmlXPathObjectPtr obj;
	/*
	* SPEC EXSLT:
	* "You can also use this function to turn a string into a text
	* node, which is helpful if you want to pass a string to a
	* function that only accepts a node-set."
	*/
	fragment = xsltCreateRVT(tctxt);
	if (fragment == NULL) {
	    xsltTransformError(tctxt, NULL, tctxt->inst,
		"exsltNodeSetFunction: Failed to create a tree fragment.\n");
	    tctxt->state = XSLT_STATE_STOPPED; 
	    return;
	}
	xsltRegisterLocalRVT(tctxt, fragment);

	strval = xmlXPathPopString (ctxt);
	
	txt = xmlNewDocText (fragment, strval);
	xmlAddChild((xmlNodePtr) fragment, txt);
	obj = xmlXPathNewNodeSet(txt);	
	if (obj == NULL) {
	    xsltTransformError(tctxt, NULL, tctxt->inst,
		"exsltNodeSetFunction: Failed to create a node set object.\n");
	    tctxt->state = XSLT_STATE_STOPPED;
	} else {
	    /*
	     * Mark it as a function result in order to avoid garbage
	     * collecting of tree fragments
	     */
	    xsltExtensionInstructionResultRegister(tctxt, obj);
	}
	if (strval != NULL)
	    xmlFree (strval);
	
	valuePush (ctxt, obj);
    }
}
Beispiel #5
0
 xmlNode* child_node_list::create_text_(const std::string& value)
 {
     xmlNode* px = xmlNewDocText(raw_->doc, detail::to_xml_chars(value.c_str()));
     if (px == 0)
     {
         std::string what = "fail to create libxml2 text node for " + value;
         throw internal_dom_error(what);
     }
     else
     {
         return px;
     }
 }
Beispiel #6
0
// Inherits XMLSpy generation source function.
void CNode::InternalSetElementValue(const tstring& sValue)
{
	xmlNodePtr pTextNode = xmlNewDocText(m_pDOMNode->doc, X(sValue));
	xmlNodePtr pChild = m_pDOMNode->children;
	if(pChild) {
		if(pChild->type == XML_TEXT_NODE) {
			xmlReplaceNode(pChild, pTextNode);
			xmlFreeNode(pChild);
		} else {
			xmlAddPrevSibling(pChild, pTextNode);
		}
	} else {
		xmlAddChild(m_pDOMNode, pTextNode);
	}
}
Beispiel #7
0
/**
 *  'insert' operation
 */
static void
edInsert(xmlDocPtr doc, xmlNodeSetPtr nodes, const char *val, const char *name,
         XmlNodeType type, int mode)
{
    int i;

    xmlXPathEmptyNodeSet(previous_insertion);

    for (i = 0; i < nodes->nodeNr; i++)
    {
        xmlNodePtr node;

        if (nodes->nodeTab[i] == (void*) doc && mode != 0) {
            fprintf(stderr, "The document node cannot have siblings.\n");
            exit(EXIT_INTERNAL_ERROR);
        }

        /* update node */
        if (type == XML_ATTR)
        {
            node = (xmlNodePtr) xmlNewProp(nodes->nodeTab[i], BAD_CAST name, BAD_CAST val);
        }
        else if (type == XML_ELEM)
        {
            node = xmlNewDocNode(doc, NULL /* TODO: NS */, BAD_CAST name, BAD_CAST val);
            if (mode > 0)
                xmlAddNextSibling(nodes->nodeTab[i], node);
            else if (mode < 0)
                xmlAddPrevSibling(nodes->nodeTab[i], node);
            else
                xmlAddChild(nodes->nodeTab[i], node);
        }
        else if (type == XML_TEXT)
        {
            node = xmlNewDocText(doc, BAD_CAST val);
            if (mode > 0)
                xmlAddNextSibling(nodes->nodeTab[i], node);
            else if (mode < 0)
                xmlAddPrevSibling(nodes->nodeTab[i], node);
            else
                xmlAddChild(nodes->nodeTab[i], node);
        }
        xmlXPathNodeSetAdd(previous_insertion, node);
    }
}
Beispiel #8
0
/**
 * article_generic_submit_serve: Submit article or reply.
 * @vr: The #VirguleReq context.
 * @title: Title, as raw text.
 * @lead: Lead, as raw text.
 * @body: Body, as raw text.
 * @olddate: Null for new posts. Original post date for edit of existing post
 * @oldkey: Null for new posts. Original article/reply key for edits
 * @submit_type: "article" or "reply".
 * @key_base: Base pathname of db key.
 * @key_suffix: Suffix of db key, after article number.
 * @art_num_str: The article number being replied to, or NULL if article.
 *
 * Submits article or reply.
 *
 * Return value: Response code.
 *
 * ToDo: There are a lot potential conflicts between char and xmlChar 
 * pointers that should be resolved to make the code more consistent.
 **/
static int
article_generic_submit_serve (VirguleReq *vr,
			      const char *topic,
			      const char *title, 
			      const char *lead, 
			      const char *body,
			      const char *olddate,
			      const char *oldkey,
			      const char *submit_type,
			      const char *key_base, 
			      const char *key_suffix,
			      const char *art_num_str)
{
  apr_pool_t *p = vr->r->pool;
  apr_table_t *args;
  Buffer *b = NULL;
  const Topic **t;
  const char *date;
  char *key;
  xmlDoc *doc;
  xmlNode *root;
  xmlNode *tree;
  int status;
  char *str = NULL;
  char *lead_error, *body_error;
  char *nice_title;
  char *nice_lead;
  char *nice_body;

  virgule_auth_user (vr);
  if (vr->u == NULL)
    return virgule_send_error_page (vr, vERROR, "forbidden", "You can't post <x>an article</x> because you're not logged in.");

  if (!virgule_req_ok_to_reply (vr))
    return virgule_send_error_page (vr, vERROR, "forbidden", "You can't post because you're not certified. Please see the <a href=\"%s/certs.html\">certification overview</a> for more details.", vr->prefix);

  date = virgule_iso_now (p);

  if (title == NULL || title[0] == 0)
    return virgule_send_error_page (vr, vERROR, "Need title", "Your <x>%s</x> needs a title. Go back and try again.", submit_type);
  if (!strcmp (submit_type, "article") && (lead == NULL || lead[0] == 0))
    return virgule_send_error_page (vr, vERROR, "Need lead", "Your <x>article</x> needs a lead. Go back and try again.");
  if (!strcmp (submit_type, "reply") && (body == NULL || body[0] == 0))
    return virgule_send_error_page (vr, vERROR, "Need body", "Your reply needs a body. Go back and try again.");

  nice_title = virgule_nice_text (p, title);
  nice_lead = lead == NULL ? "" : virgule_nice_htext (vr, lead, &lead_error);
  nice_body = body == NULL ? "" : virgule_nice_htext (vr, body, &body_error);

  args = virgule_get_args_table (vr);
  if(olddate != NULL)
    apr_table_set (args, "preview", "Preview");
  else
    olddate = apr_table_get (args, "olddate");
  if(oldkey == NULL)
    oldkey = apr_table_get (args, "oldkey");

  if (apr_table_get (args, "preview"))
    {
      /* render a preview */
      if (virgule_set_temp_buffer (vr) != 0)
        return HTTP_INTERNAL_SERVER_ERROR;

      b = vr->b;

      if (!strcmp (submit_type, "reply"))
	{
          str = apr_pstrdup (p, "Reply preview");
	  virgule_render_cert_level_begin (vr, vr->u, CERT_STYLE_MEDIUM);
	  virgule_buffer_printf (b, "<font size=+2><b>%s</b></font><br>\n", nice_title);
	  virgule_render_cert_level_end (vr, CERT_STYLE_MEDIUM);
	  virgule_buffer_printf (b, "<p>%s</p>\n", nice_body);
	  virgule_buffer_puts (b, "<hr>\n");
	  virgule_buffer_printf (b, "<p>Edit your reply:</p>\n"
			 "<form method=\"POST\" action=\"replysubmit.html\" accept-charset=\"UTF-8\">\n"
			 "<p><x>Article</x> title: <br>\n"
			 "<input type=\"text\" name=\"title\" value=\"%s\" size=\"40\" maxlength=\"60\"></p>\n"
			 "<p>Body of <x>article</x>: <br>\n"
			 "<textarea name=\"body\" cols=\"72\" rows=\"16\" wrap=\"hard\">%s"
			 "</textarea></p>\n"
			 "<input type=\"hidden\" name=\"art_num\" value=\"%s\">\n"
			 "<p><input type=\"submit\" name=\"post\" value=\"Post\">\n"
			 "<input type=\"submit\" name=\"preview\" value=\"Preview\">\n"
			 "</form>\n",
			 virgule_str_subst (p, title, "\"", "&quot;"),
			 ap_escape_html (p, body),
			 art_num_str);
	  
	  virgule_render_acceptable_html (vr);
	}
      else if (!strcmp (submit_type, "article"))
	{
          str = apr_pstrdup (p, "<x>Article</x>  preview");
	  if(vr->priv->use_article_topics)
	    {
	      virgule_buffer_puts (b, "<table><tr><td>");
              article_render_topic (vr, (char *)topic);
              virgule_buffer_puts (b, "</td><td>");
	    }
          virgule_render_cert_level_begin (vr, vr->u, CERT_STYLE_LARGE);
          virgule_buffer_printf (b, "<span class=\"article-title\">%s</span>",nice_title);
          virgule_render_cert_level_end (vr, CERT_STYLE_LARGE);
	  
	  if(vr->priv->use_article_topics)
            virgule_buffer_puts (b, "</td></tr></table>\n");

	  virgule_buffer_printf (b, "<p>%s</p>\n", nice_lead);
	  virgule_buffer_printf (b, "<p>%s</p>\n", nice_body);
	  virgule_buffer_puts (b, "<hr>\n");
	  virgule_buffer_puts (b, "<p>Edit your <x>article</x>:</p>\n"
		"<form method=\"POST\" action=\"postsubmit.html\" accept-charset=\"UTF-8\">\n");

          if(olddate && oldkey)
	    {
	      virgule_buffer_printf (b, "<input type=\"hidden\" name=\"olddate\" value=\"%s\" />\n", olddate);
	      virgule_buffer_printf (b, "<input type=\"hidden\" name=\"oldkey\" value=\"%s\" />\n", oldkey);
	    }
	    
	  if(vr->priv->use_article_topics)
	    {
	      virgule_buffer_puts (b, "<p><b><x>Article</x> topic</b>:<br>\n <select name=\"topic\">\n");

              for (t = vr->priv->topics; *t; t++)
	        virgule_buffer_printf (b, "<option%s>%s</option>\n",
		  strcmp((*t)->desc,topic) ? "" : " selected",(*t)->desc);

	      virgule_buffer_puts (b, " </select></p>\n");
	    }

	  virgule_buffer_printf (b,
			 "<p><b><x>Article</x> title</b>:<br>\n"
			 "<input type=\"text\" name=\"title\" value=\"%s\" size=\"40\" maxlength=\"%i\"></p>\n"
	        	 "<p><b><x>Article</x> lead</b>. This should be a one paragraph summary "
	    		 "of the story complete with links to the original "
	    		 "sources when appropriate.<br>"			 
			 "<textarea name=\"lead\" cols=72 rows=6 wrap=hard>%s"
			 "</textarea> </p>\n",
			 virgule_str_subst (p, title, "\"", "&quot;"),
			 vr->priv->article_title_maxsize,
			 ap_escape_html (p, lead));
	  if (lead_error != NULL)
	    virgule_buffer_printf (b, "<p><b>Warning:</b> %s</p>\n", lead_error);

	  virgule_buffer_printf (b,"<p><b><x>Article</x> Body</b>. This should "
	    		 "contain the body of your article and may be as long as "
			 "needed. If your entire article is only one paragraph, "
			 "put it in the lead field above and leave this one empty<br>"
			 "<textarea name=\"body\" cols=72 rows=16 wrap=hard>%s"
			 "</textarea></p>\n"
			 "<p><b>Warning:</b> Please proof read your article "
			 "and verify spelling and any html markup before posting. "
			 "Click the <b>Preview</b> button to see changes. Once "
			 "you click the <b>Post</b> button your article will be "
			 "posted and changes are no longer possible."
			 "<p><input type=\"submit\" name=post value=\"Post\">\n"
			 "<input type=\"submit\" name=preview value=\"Preview\">\n"
			 "</form>\n",
			 ap_escape_html (p, (body ? body : "")));
	  if (body_error != NULL)
	    virgule_buffer_printf (b, "<p><b>Warning:</b> %s </p>\n", body_error);

	  virgule_render_acceptable_html (vr);

	}
	virgule_set_main_buffer (vr);
	return virgule_render_in_template (vr, "/templates/default.xml", "content", str);
    }

  key = apr_psprintf (p, "%s/_%d%s",
		      key_base,
		      oldkey ? atoi (oldkey) : virgule_db_dir_max (vr->db, key_base) + 1,
		      key_suffix);

  doc = virgule_db_xml_doc_new (p);
  root = xmlNewDocNode (doc, NULL, (xmlChar *)"article", NULL);
  doc->xmlRootNode = root;

  if(olddate != NULL)
    {
      xmlNewChild (root, NULL, (xmlChar *)"date", (xmlChar *)olddate);
      xmlNewChild (root, NULL, (xmlChar *)"update", (xmlChar *)date);
    }
  else
    {
      tree = xmlNewChild (root, NULL, (xmlChar *)"date", (xmlChar *)date);
    }
  tree = xmlNewChild (root, NULL, (xmlChar *)"author", (xmlChar *)vr->u);

  tree = xmlNewChild (root, NULL, (xmlChar *)"title", NULL);
  xmlAddChild (tree, xmlNewDocText (doc, (xmlChar *)nice_title));

  if(vr->priv->use_article_topics)
    {
      tree = xmlNewChild (root, NULL, (xmlChar *)"topic", NULL);
      xmlAddChild (tree, xmlNewDocText (doc, (xmlChar *)topic));
    }

  if (lead && lead[0])
    {
      tree = xmlNewChild (root, NULL, (xmlChar *)"lead", NULL);
      xmlAddChild (tree, xmlNewDocText (doc, (xmlChar *)nice_lead));
    }

  if (body != NULL && body[0])
    {
      tree = xmlNewChild (root, NULL, (xmlChar *)"body", NULL);
      xmlAddChild (tree, xmlNewDocText (doc, (xmlChar *)nice_body));
    }

  /* sanity-check edit qualifications before saving */
  if (olddate || oldkey) 
    {
      char *a, *d;
      time_t t;
      xmlNodePtr r;
      int art_num = atoi (oldkey);
      char *k = apr_psprintf (vr->r->pool, "articles/_%d/article.xml", art_num);
      xmlDocPtr old = virgule_db_xml_get (vr->r->pool, vr->db, k);
      if (old == NULL)
        return virgule_send_error_page (vr, vERROR, "not found", "The specified <x>article</x> does not exist.");
      r = xmlDocGetRootElement (old);

      /* verify the article is not too old to edit */
      d = virgule_xml_find_child_string (r, "date", NULL);
      t = virgule_virgule_to_time_t (vr, d);
      if (t + (vr->priv->article_days_to_edit * 86400) < time (NULL))
        return virgule_send_error_page (vr, vERROR, "forbidden", "This <x>article</x> is too old to be edited.");

      /* verify this user can edit this article */
      a = virgule_xml_find_child_string (r, "author", NULL);
      if (strcmp (vr->u, a))
        return virgule_send_error_page (vr, vERROR, "forbidden", "Only <x>articles</x> posted by you may be edited.");
    }

  status = virgule_db_xml_put (p, vr->db, key, doc);

  if (status)
    return virgule_send_error_page (vr, vERROR,
			    "database",
			    "There was an error storing the <x>%s</x>. This means there's something wrong with the site.", submit_type);

  if (!strcmp (submit_type, "reply"))
    apr_table_add (vr->r->headers_out, "refresh", 
		  apr_psprintf(p, "0;URL=/article/%s.html#lastread", art_num_str));
  else 
    apr_table_add (vr->r->headers_out, "refresh", 
		  apr_psprintf(p, "0;URL=/article/%d.html", 
		              oldkey ? atoi (oldkey) : virgule_db_dir_max (vr->db, key_base)));

  str = apr_psprintf (p, "Ok, your <x>%s</x> was posted. Thanks!", submit_type);
  return virgule_send_error_page (vr, vINFO, "Posted", str);
}