Example #1
0
void
bg_nle_media_list_save(bg_nle_media_list_t * list, xmlNodePtr node)
  {
  char * tmp_string;
  int i;
  xmlNodePtr child;
  xmlNodePtr grandchild;
  
  if(list->open_path)
    {
    child = xmlNewTextChild(node, (xmlNsPtr)0,
                            (xmlChar*)open_path_name, NULL);
    xmlAddChild(child, BG_XML_NEW_TEXT(list->open_path));
    }

  if(list->num_files)
    {
    child = xmlNewTextChild(node, (xmlNsPtr)0,
                            (xmlChar*)files_name, NULL);
    tmp_string = bg_sprintf("%d", list->num_files);
    BG_XML_SET_PROP(child, "num", tmp_string);
    free(tmp_string);

    for(i = 0; i < list->num_files; i++)
      {
      grandchild = xmlNewTextChild(child, (xmlNsPtr)0,
                                   (xmlChar*)file_name, NULL);

      bg_nle_file_save(grandchild, list->files[i]);
      }
    }
  
  }
Example #2
0
static void save_audio_stream(xmlNodePtr node,
                              bg_nle_audio_stream_t * s)
  {
  xmlNodePtr child;
  char * tmp_string;
  /* Timescale */
  tmp_string = bg_sprintf("%d", s->timescale);
  BG_XML_SET_PROP(node, "scale", tmp_string);
  free(tmp_string);
  
  /* Offset */
  child = xmlNewTextChild(node, (xmlNsPtr)0,
                          (xmlChar*)start_time_name, NULL);
  
  tmp_string = bg_sprintf("%"PRId64, s->start_time);
  xmlAddChild(child, BG_XML_NEW_TEXT(tmp_string));
  free(tmp_string);

  /* Duration */
  child = xmlNewTextChild(node, (xmlNsPtr)0,
                          (xmlChar*)duration_name, NULL);
  tmp_string = bg_sprintf("%"PRId64, s->duration);
  xmlAddChild(child, BG_XML_NEW_TEXT(tmp_string));
  free(tmp_string);
  
  }
Example #3
0
static void save_video_stream(xmlNodePtr node,
                              bg_nle_video_stream_t * s)
  {
  char * tmp_string;
  xmlNodePtr child;

  /* Timescale */
  tmp_string = bg_sprintf("%d", s->timescale);
  BG_XML_SET_PROP(node, "scale", tmp_string);
  free(tmp_string);

  if(s->tc_format.int_framerate)
    {
    child = xmlNewTextChild(node, (xmlNsPtr)0,
                            (xmlChar*)tc_rate_name, NULL);
    
    tmp_string = bg_sprintf("%d", s->tc_format.int_framerate);
    xmlAddChild(child, BG_XML_NEW_TEXT(tmp_string));
    free(tmp_string);
    }
  if(s->tc_format.flags)
    {
    child = xmlNewTextChild(node, (xmlNsPtr)0,
                            (xmlChar*)tc_flags_name, NULL);
    
    tmp_string = bg_sprintf("%d", s->tc_format.flags);
    xmlAddChild(child, BG_XML_NEW_TEXT(tmp_string));
    free(tmp_string);
    }
  
  }
Example #4
0
int main (int argc, char **argv)
{
  xmlDocPtr pdoc = NULL;
  xmlNodePtr proot_node = NULL,pnode = NULL,pnode1 = NULL;

  // 创建一个新文档并设置 root 节点
  // 一个 XML 文件只有一个 root 节点
  pdoc = xmlNewDoc (BAD_CAST "1.0");
  proot_node = xmlNewNode (NULL, BAD_CAST "根节点");
  xmlNewProp (proot_node, BAD_CAST "版本", BAD_CAST "1.0");
  xmlDocSetRootElement (pdoc, proot_node);

  pnode = xmlNewNode (NULL, BAD_CAST "子节点1");
  // 创建上面 pnode 的子节点
  xmlNewChild (pnode, NULL, BAD_CAST "子子节点1", BAD_CAST "信息");
  // 添加子节点到 root 节点
  xmlAddChild (proot_node, pnode);

  pnode1 = xmlNewNode (NULL, BAD_CAST "子子节点1");
  xmlAddChild (pnode, pnode1);
  xmlAddChild (pnode1,xmlNewText (BAD_CAST "这是更低的节点,子子子节点1"));

  // 还可以这样直接创建一个子节点到 root 节点上
  xmlNewTextChild (proot_node, NULL, BAD_CAST "子节点2", BAD_CAST "子节点2的内容");
  xmlNewTextChild (proot_node, NULL, BAD_CAST "子节点3", BAD_CAST "子节点3的内容");

  // 保存 xml 为文件,如果没有给出文件名参数,就输出到标准输出
  xmlSaveFormatFileEnc (argc > 1 ? argv[1]:"-", pdoc, "UTF-8", 1);

  // 释放资源
  xmlFreeDoc (pdoc);
  xmlCleanupParser ();
  xmlMemoryDump ();
  return 0;
}
Example #5
0
static void
xml_subprocess_output(pcmk__output_t *out, int exit_status,
                      const char *proc_stdout, const char *proc_stderr) {
    xmlNodePtr node, child_node;
    char *rc_as_str = NULL;
    xml_private_t *priv = out->priv;
    CRM_ASSERT(priv != NULL);

    rc_as_str = crm_itoa(exit_status);

    node = xmlNewNode(g_queue_peek_tail(priv->parent_q), (pcmkXmlStr) "command");
    xmlSetProp(node, (pcmkXmlStr) "code", (pcmkXmlStr) rc_as_str);

    if (proc_stdout != NULL) {
        child_node = xmlNewTextChild(node, NULL, (pcmkXmlStr) "output",
                                     (pcmkXmlStr) proc_stdout);
        xmlSetProp(child_node, (pcmkXmlStr) "source", (pcmkXmlStr) "stdout");
    }

    if (proc_stderr != NULL) {
        child_node = xmlNewTextChild(node, NULL, (pcmkXmlStr) "output",
                                     (pcmkXmlStr) proc_stderr);
        xmlSetProp(node, (pcmkXmlStr) "source", (pcmkXmlStr) "stderr");
    }

    pcmk__xml_add_node(out, node);
    free(rc_as_str);
}
Example #6
0
void save_languages_to_xml (language * languages, int size)
{
	xmlDocPtr doc;
	xmlNodePtr parent, child;
	xmlXPathContextPtr xpathCtx;
	xmlXPathObjectPtr xpathObj;
	int i;
	
	xmlKeepBlanksDefault(0);
	doc = xmlNewDoc (BAD_CAST "1.0");

	parent = xmlNewNode(NULL, "languages");
	xmlDocSetRootElement(doc, parent);

	for(i=0; i<size; i++)
	{
		child = xmlNewTextChild (parent, NULL, "lang", NULL);
		xmlNewTextChild (child, NULL, "name", languages->name);
		xmlNewTextChild (child, NULL, "code", languages->code);
		xmlNewTextChild (child, NULL, "flag", languages->flag);
		languages++;
	}

	xmlSaveFormatFile ("src/config/languages.xml", doc, 1);
	xmlFreeDoc(doc);
}
static void
battmon_write_config(Control *ctrl, xmlNodePtr parent)
{
	xmlNodePtr root;
	char value[MAXSTRLEN + 1];

	t_battmon *battmon = (t_battmon *) ctrl->data;

	root = xmlNewTextChild(parent, NULL, "BatteryMonitor", NULL);
	/* Display Percentage */
	g_snprintf(value, 2, "%d", battmon->options.display_percentage);
	xmlSetProp(root, "display_percentage", value);
	/* Display Percentage in Tooltip */
	g_snprintf(value, 2, "%d", battmon->options.tooltip_display_percentage);
	xmlSetProp(root, "tooltip_display_percentage", value);
	/* Display Time in Tooltip */
	g_snprintf(value, 2, "%d", battmon->options.tooltip_display_time);
	xmlSetProp(root, "tooltip_display_time", value);
	/* Low Percentage */
	g_snprintf(value, 4, "%d", battmon->options.low_percentage);
	xmlSetProp(root, "low_percentage", value);
	/* Critical Percentage */
	g_snprintf(value, 4, "%d", battmon->options.critical_percentage);
	xmlSetProp(root, "critical_percentage", value);
	/* Action on Low */
	g_snprintf(value, 2, "%d", battmon->options.action_on_low);
	xmlSetProp(root, "action_on_low", value);
	/* Action on Critical */
	g_snprintf(value, 2, "%d", battmon->options.action_on_critical);
	xmlSetProp(root, "action_on_critical", value);
	/* Command on Low */
	xmlNewTextChild(root, NULL, "command_on_low", battmon->options.command_on_low);
	/* Command on Critical */
	xmlNewTextChild(root, NULL, "command_on_critical", battmon->options.command_on_critical);
}
Example #8
0
xmlNodePtr   playlist_render_xspf(playlist_t *playlist)
{
    xmlNodePtr rootnode, tracklist, tracknode;
    playlist_track_t *track;

    if (!playlist)
        return NULL;

    rootnode = xmlNewNode(NULL, XMLSTR("playlist"));
    xmlSetProp(rootnode, XMLSTR("version"), XMLSTR("1"));
    xmlSetProp(rootnode, XMLSTR("xmlns"), XMLSTR("http://xspf.org/ns/0/"));

    tracklist = xmlNewNode(NULL, XMLSTR("trackList"));
    xmlAddChild(rootnode, tracklist);

    track = playlist->first;
    while (track) {
        tracknode = xmlNewNode(NULL, XMLSTR("track"));
        xmlAddChild(tracklist, tracknode);
        /* TODO: Handle meta data */
        if (track->title)
            xmlNewTextChild(tracknode, NULL, XMLSTR("title"), XMLSTR(track->title));
        if (track->creator)
            xmlNewTextChild(tracknode, NULL, XMLSTR("creator"), XMLSTR(track->creator));
        if (track->album)
            xmlNewTextChild(tracknode, NULL, XMLSTR("album"), XMLSTR(track->album));
        if (track->trackNum)
            xmlNewTextChild(tracknode, NULL, XMLSTR("trackNum"), XMLSTR(track->trackNum));
        track = track->next;
    }

    return rootnode;
}
Example #9
0
static xmlNodePtr
organization_to_xmlnode (GDataEntryOrganization *organization)
{

	xmlNodePtr organization_node;

	organization_node = xmlNewNode(NULL, (xmlChar *)"organization");
	xmlSetNs (organization_node, xmlNewNs (organization_node, NULL, (xmlChar *)"gd"));
	if (organization->rel)
		xmlSetProp (organization_node, (xmlChar *)"rel", (xmlChar *)organization->rel);

	if (organization->label)
		xmlSetProp (organization_node, (xmlChar *)"label", (xmlChar *)organization->label);
	
	if (organization->primary)
		xmlSetProp (organization_node, (xmlChar *)"primary", (xmlChar *)"true");

	if (organization->name)
		xmlNewTextChild (organization_node, NULL, (xmlChar *)"orgName", (xmlChar *)organization->name);

	if (organization->title)
		xmlNewTextChild (organization_node, NULL, (xmlChar *)"orgTitle", (xmlChar *)organization->title);

	return organization_node;
}
static void monitor_write_config(Control *ctrl, xmlNodePtr parent)
{
    xmlNodePtr root;
    char value[20];
    t_global_monitor *global;

    global = (t_global_monitor *)ctrl->data;

    root = xmlNewTextChild(parent, NULL, MONITOR_ROOT, NULL);

    g_snprintf(value, 2, "%d", global->monitor->options.use_label);
    xmlSetProp(root, "Use_Label", value);

    g_snprintf(value, 8, "#%02X%02X%02X",
               (guint)global->monitor->options.color[IN].red >> 8,
               (guint)global->monitor->options.color[IN].green >> 8,
               (guint)global->monitor->options.color[IN].blue >> 8);

    xmlSetProp(root, "Color_In", value);

    g_snprintf(value, 8, "#%02X%02X%02X",
               (guint)global->monitor->options.color[OUT].red >> 8,
               (guint)global->monitor->options.color[OUT].green >> 8,
               (guint)global->monitor->options.color[OUT].blue >> 8);

    xmlSetProp(root, "Color_Out", value);

    if (global->monitor->options.label_text) 
    {
        xmlSetProp(root, "Text",
                   global->monitor->options.label_text);
    }
    else 
    {
        xmlSetProp(root, "Text", DEFAULT_TEXT);
    }

    if (global->monitor->options.network_device)
    {
        xmlSetProp(root, "Network_Device", global->monitor->options.network_device);
    }
    else
    {
        xmlSetProp(root, "Network_Device", DEFAULT_DEVICE);
    }
    
    g_snprintf(value, 20, "%lu", global->monitor->options.max[IN]);
    xmlSetProp(root, "Max_In", value);
    
    g_snprintf(value, 20, "%lu", global->monitor->options.max[OUT]);
    xmlSetProp(root, "Max_Out", value);
    
    g_snprintf(value, 2, "%d", global->monitor->options.auto_max);
    xmlSetProp(root, "Auto_Max", value);
    
    g_snprintf(value, 20, "%d", global->monitor->options.update_interval);
    xmlSetProp(root, "Update_Interval", value);
    
    root = xmlNewTextChild(parent, NULL, MONITOR_ROOT, NULL);
}
Example #11
0
void bg_upnp_device_description_add_icon(xmlDocPtr ptr,
        const char * mimetype,
        int width, int height, int depth, const char * url)
{
    char * tmp_string;
    xmlNodePtr iconlist;
    xmlNodePtr icon;
    xmlNodePtr node = get_device_node(ptr);

    iconlist = bg_xml_find_node_child(node, "iconList");
    if(!iconlist)
        iconlist = xmlNewTextChild(node, NULL, (xmlChar*)"iconList", NULL);

    icon = xmlNewTextChild(iconlist, NULL, (xmlChar*)"icon", NULL);
    bg_xml_append_child_node(icon, "mimetype", mimetype);

    tmp_string = bg_sprintf("%d", width);
    bg_xml_append_child_node(icon, "width", tmp_string);
    free(tmp_string);

    tmp_string = bg_sprintf("%d", height);
    bg_xml_append_child_node(icon, "height", tmp_string);
    free(tmp_string);

    tmp_string = bg_sprintf("%d", depth);
    bg_xml_append_child_node(icon, "depth", tmp_string);
    free(tmp_string);

    bg_xml_append_child_node(icon, "url", url);
}
Example #12
0
static xmlNodePtr
add_group (GPInstructLessonElementGroup *group,
           xmlNodePtr parent_node)
{
	GPInstructLessonElement *curr_lesson_element;

	GList *lesson_elements;
	GList *curr_lesson_elements;

	xmlNodePtr current_node = xmlNewTextChild (parent_node, NULL,
	                                           BAD_CAST "group", NULL);
	xmlSetProp (current_node, BAD_CAST "title",
	            BAD_CAST gpinstruct_lesson_element_get_title (GPINSTRUCT_LESSON_ELEMENT (group)));
	xmlSetProp (current_node, BAD_CAST "single-score",
	            gpinstruct_lesson_element_group_get_single_score (group)?BAD_CAST "true":BAD_CAST "false");
	xmlSetProp (current_node, BAD_CAST "single-directions",
	            gpinstruct_lesson_element_group_get_single_directions (group)?BAD_CAST "true":BAD_CAST "false");

	xmlNewTextChild (current_node, NULL, BAD_CAST "directions",
	                 BAD_CAST gpinstruct_lesson_element_group_get_directions (group));

	lesson_elements = gpinstruct_lesson_element_group_get_lesson_elements (group);
	curr_lesson_elements = lesson_elements;

	while (curr_lesson_elements)
	{
		curr_lesson_element = GPINSTRUCT_LESSON_ELEMENT (curr_lesson_elements->data);

		if (GPINSTRUCT_IS_LESSON_DISCUSSION (curr_lesson_element))
			add_discussion (GPINSTRUCT_LESSON_DISCUSSION (curr_lesson_element),
			                current_node);
		else if (GPINSTRUCT_IS_LESSON_READING (curr_lesson_element))
			add_reading (GPINSTRUCT_LESSON_READING (curr_lesson_element),
			             current_node);
		else if (GPINSTRUCT_IS_LESSON_TEST_MULTI_CHOICE (curr_lesson_element))
			add_multi_choice_test (GPINSTRUCT_LESSON_TEST_MULTI_CHOICE (curr_lesson_element),
			                       current_node);
		else if (GPINSTRUCT_IS_LESSON_TEST_WORD_POOL (curr_lesson_element))
			add_word_pool_test (GPINSTRUCT_LESSON_TEST_WORD_POOL (curr_lesson_element),
			                    current_node);
		else if (GPINSTRUCT_IS_LESSON_TEST_ORDER (curr_lesson_element))
			add_order_test (GPINSTRUCT_LESSON_TEST_ORDER (curr_lesson_element),
			                current_node);
		else if (GPINSTRUCT_IS_LESSON_TEST_TEXT (curr_lesson_element))
			add_text_test (GPINSTRUCT_LESSON_TEST_TEXT (curr_lesson_element),
			               current_node);
		else if (GPINSTRUCT_IS_LESSON_TEST_SCRAMBLED (curr_lesson_element))
			add_scrambled_test (GPINSTRUCT_LESSON_TEST_SCRAMBLED (curr_lesson_element),
			                    current_node);

		curr_lesson_elements = curr_lesson_elements->next;
	}

	g_list_free (lesson_elements);

	return current_node;
}
static gboolean
chatroom_manager_file_save (EmpathyChatroomManager *manager)
{
  EmpathyChatroomManagerPriv *priv;
  xmlDocPtr doc;
  xmlNodePtr root;
  GList *l;

  priv = GET_PRIV (manager);

  priv->writing = TRUE;

  doc = xmlNewDoc ((const xmlChar *) "1.0");
  root = xmlNewNode (NULL, (const xmlChar *) "chatrooms");
  xmlDocSetRootElement (doc, root);

  for (l = priv->chatrooms; l; l = l->next)
    {
      EmpathyChatroom *chatroom;
      xmlNodePtr       node;
      const gchar     *account_id;

      chatroom = l->data;

      if (!empathy_chatroom_is_favorite (chatroom))
        continue;

      account_id = tp_proxy_get_object_path (empathy_chatroom_get_account (
            chatroom));

      node = xmlNewChild (root, NULL, (const xmlChar *) "chatroom", NULL);
      xmlNewTextChild (node, NULL, (const xmlChar *) "name",
        (const xmlChar *) empathy_chatroom_get_name (chatroom));
      xmlNewTextChild (node, NULL, (const xmlChar *) "room",
        (const xmlChar *) empathy_chatroom_get_room (chatroom));
      xmlNewTextChild (node, NULL, (const xmlChar *) "account",
        (const xmlChar *) account_id);
      xmlNewTextChild (node, NULL, (const xmlChar *) "auto_connect",
        empathy_chatroom_get_auto_connect (chatroom) ?
        (const xmlChar *) "yes" : (const xmlChar *) "no");
      xmlNewTextChild (node, NULL, (const xmlChar *) "always_urgent",
        empathy_chatroom_is_always_urgent (chatroom) ?
        (const xmlChar *) "yes" : (const xmlChar *) "no");
    }

  /* Make sure the XML is indented properly */
  xmlIndentTreeOutput = 1;

  DEBUG ("Saving file:'%s'", priv->file);
  xmlSaveFormatFileEnc (priv->file, doc, "utf-8", 1);
  xmlFreeDoc (doc);

  xmlMemoryDump ();

  priv->writing = FALSE;
  return TRUE;
}
Example #14
0
File: webdav.c Project: JuanS/uwsgi
static void uwsgi_webdav_add_a_prop(xmlNode *node, char *opt, xmlNode *req_prop, int type, char *force_name) {
	char *first_space = strchr(opt, ' ');
	if (!first_space) return;
	*first_space = 0;
	char *second_space = strchr(first_space + 1, ' ');
	xmlNode *new_node = NULL;
	char *ns = opt;
	if (!force_name) force_name = first_space + 1;
	else {
		ns = "DAV:";
	}
	if (second_space) {
		*second_space = 0;
		if (!uwsgi_webdav_prop_requested(req_prop, ns, force_name)) {
                	*first_space = ' ';
                        *second_space = ' ';
                        return;
                }
		// href
		if (type == 1) {
			new_node = xmlNewChild(node, NULL, BAD_CAST first_space + 1, NULL);
			xmlNewTextChild(new_node, NULL, BAD_CAST "href", BAD_CAST second_space + 1);
		}
		// comp
		else if (type == 2) {
			new_node = xmlNewChild(node, NULL, BAD_CAST first_space + 1, NULL);
			char *comps = uwsgi_str(second_space + 1);
			char *p = strtok(comps, ",");
			while(p) {
				xmlNode *comp = xmlNewChild(new_node, NULL, BAD_CAST "comp", NULL);
				xmlNewProp(comp, BAD_CAST "name", BAD_CAST p);
				p = strtok(NULL, ",");
			}
			free(comps);
		}
		else {
			if (!uwsgi_webdav_prop_requested(req_prop, ns, first_space + 1)) {
                                *first_space = ' ';
                                *second_space = ' ';
                                return;
                        }
			new_node = xmlNewTextChild(node, NULL, BAD_CAST first_space + 1, BAD_CAST second_space + 1);
		}
		*second_space = ' ';
	}
	else {
		if (!uwsgi_webdav_prop_requested(req_prop, ns, force_name)) {
                        *first_space = ' ';
                        return;
                }
		new_node = xmlNewChild(node, NULL, BAD_CAST first_space + 1, NULL);
	}
	xmlNsPtr x_ns = xmlNewNs(new_node, BAD_CAST opt, NULL);
	xmlSetNs(new_node, x_ns);
	*first_space = ' ';
}
Example #15
0
static int
build_key (pskc_key_t * kp, xmlNodePtr keyp)
{
  const char *id = pskc_get_key_id (kp);
  const char *alg = pskc_get_key_algorithm (kp);
  const char *issuer = pskc_get_key_issuer (kp);
  const char *userid = pskc_get_key_userid (kp);
  const char *keyprofileid = pskc_get_key_profileid (kp);
  const char *keyreference = pskc_get_key_reference (kp);
  const char *friendlyname = pskc_get_key_friendlyname (kp);
  xmlNodePtr key;
  int rc;

  key = xmlNewChild (keyp, NULL, BAD_CAST "Key", NULL);

  if (id && xmlNewProp (key, BAD_CAST "Id", BAD_CAST id) == NULL)
    return PSKC_XML_ERROR;

  if (alg && xmlNewProp (key, BAD_CAST "Algorithm", BAD_CAST alg) == NULL)
    return PSKC_XML_ERROR;

  if (issuer &&
      xmlNewTextChild (key, NULL, BAD_CAST "Issuer", BAD_CAST issuer) == NULL)
    return PSKC_XML_ERROR;

  rc = build_algparm (kp, key);
  if (rc != PSKC_OK)
    return rc;

  if (keyprofileid && xmlNewTextChild (key, NULL, BAD_CAST "KeyProfileId",
				       BAD_CAST keyprofileid) == NULL)
    return PSKC_XML_ERROR;

  if (keyreference && xmlNewTextChild (key, NULL, BAD_CAST "KeyReference",
				       BAD_CAST keyreference) == NULL)
    return PSKC_XML_ERROR;

  if (friendlyname && xmlNewTextChild (key, NULL, BAD_CAST "FriendlyName",
				       BAD_CAST friendlyname) == NULL)
    return PSKC_XML_ERROR;

  rc = build_data (kp, key);
  if (rc != PSKC_OK)
    return rc;

  if (userid && xmlNewTextChild (key, NULL, BAD_CAST "UserId",
				 BAD_CAST userid) == NULL)
    return PSKC_XML_ERROR;

  rc = build_policy (kp, key);
  if (rc != PSKC_OK)
    return rc;

  return PSKC_OK;
}
Example #16
0
int LocalPackage::injectFile()
{
	if (!dialogMode && verbose) say(string(_("Injecting file") + filename + "\n").c_str());

	internal=true;
	// Injecting data from file!
	// If any of functions fails (e.g. return!=0) - break process and return failure code (!=0);
	//int ret=0;
	//mDebug("local_package.cpp: injectFile(): start");
	//mDebug("get_xml");
	if (get_xml()!=0)
	{
		//mDebug("local_package.cpp: injectFile(): get_xml FAILED");
		return -3;
	}
	if (getExtension(filename)=="spkg") {
		//printf("Source package detected, adding to XML\n");
		xmlNewTextChild(_packageXMLNode, NULL, (const xmlChar *)"type", (const xmlChar *)"source");
		data.set_type(PKGTYPE_SOURCE);
	}
	if (getExtension(filename)=="tgz" || getExtension(filename) == "txz" || getExtension(filename) == "tlz" ||getExtension(filename) == "tbz" ) {
		xmlNewTextChild(_packageXMLNode, NULL, (const xmlChar *)"type", (const xmlChar *)"binary");
		data.set_type(PKGTYPE_BINARY);
	}

	


	//mDebug("get_size()\n");
	if (get_size()!=0)
	{
		mDebug("local_package.cpp: injectFile(): get_size() FAILED");
		return -1;
	}
	//mDebug("create_md5\n");
	if (create_md5()!=0)
	{
		mDebug("local_package.cpp: injectFile(): create_md5 FAILED");
		return -2;
	}
	//mDebug("set_additional_data\n");
	//mDebug("local_packaige.cpp: injectFile(): filename is "+ filename);
	data.set_filename(filename);
	
	if (set_additional_data()!=0)
	{
		mDebug("local_package.cpp: injectFile(): set_additional_data FAILED");
		return -6;
	}
	delete_tmp_files();	
	//mDebug("local_package.cpp: injectFile(): end");
	return 0;
}
Example #17
0
int
messageCreateClientAuthentication(
        unsigned char *masterkeySignature, int signatureSize,
        char *name, int nameSize,
        char *numBI, int numBISize,
        char *userName, int userNameSize,
        char *hostName, int hostNameSize,
        char *message, int messageMaxSize)
{
    xmlChar *s;
    xmlDocPtr doc = NULL;       /* document pointer */
    xmlNodePtr root_node = NULL;/* node pointers */
    int result;
    int messageSize;
    char *sigBase64;

    sigBase64 = b64encode(masterkeySignature, signatureSize);

    LIBXML_TEST_VERSION;

    doc = xmlNewDoc(BAD_CAST "1.0");
    root_node = xmlNewNode(NULL, BAD_CAST "authentication");
    xmlDocSetRootElement(doc, root_node);

    xmlSetProp(root_node, BAD_CAST "type", BAD_CAST "clientAuthentication");

    xmlNewChild(root_node, NULL, BAD_CAST "secretSignature",BAD_CAST sigBase64);

    root_node = xmlNewChild(root_node, NULL,BAD_CAST "clientInfo", NULL);

    xmlNewTextChild(root_node, NULL, BAD_CAST "nBI",BAD_CAST numBI);
    xmlNewTextChild(root_node, NULL, BAD_CAST "name",BAD_CAST name);
    xmlNewTextChild(root_node, NULL, BAD_CAST "userName",BAD_CAST userName);
    xmlNewTextChild(root_node, NULL, BAD_CAST "hostName",BAD_CAST hostName);
    

    xmlDocDumpMemory(doc, &s, &messageSize);

    if( messageSize + 1 <= messageMaxSize)
    {
        strcpy((char *) message, (char *) s);
        result = messageSize + 1;
    }       
    else
        result = -1;
    free(sigBase64);
   xmlFree(s);
    xmlFreeDoc(doc);
    xmlCleanupParser();

    return result;
}
Example #18
0
void
subscription_to_xml (subscriptionPtr subscription, xmlNodePtr xml)
{
	gchar	*tmp;
	
	xmlNewTextChild (xml, NULL, "feedSource", subscription_get_source (subscription));
	xmlNewTextChild (xml, NULL, "feedOrigSource", subscription_get_orig_source (subscription));

	tmp = g_strdup_printf ("%d", subscription_get_default_update_interval (subscription));
	xmlNewTextChild (xml, NULL, "feedUpdateInterval", tmp);
	g_free (tmp);

	tmp = g_strdup_printf ("%d", subscription->discontinued?1:0);
	xmlNewTextChild (xml, NULL, "feedDiscontinued", tmp);
	g_free (tmp);

	if (subscription->updateError)
		xmlNewTextChild (xml, NULL, "updateError", subscription->updateError);
	if (subscription->httpError) {
		xmlNewTextChild (xml, NULL, "httpError", subscription->httpError);

		tmp = g_strdup_printf ("%d", subscription->httpErrorCode);
		xmlNewTextChild (xml, NULL, "httpErrorCode", tmp);
		g_free (tmp);
	}
	if (subscription->filterError)
		xmlNewTextChild (xml, NULL, "filterError", subscription->filterError);

	metadata_add_xml_nodes (subscription->metadata, xml);
}
Example #19
0
int LocalPackage::get_size()
{
	string csize, isize;
	struct stat fstat;
	stat(filename.c_str(), &fstat);
	isize = getExtractedSize(filename);
	data.set_installed_size(isize);
	csize = IntToStr(fstat.st_size);
	data.set_compressed_size(csize);

	xmlNewTextChild(_packageXMLNode, NULL, (const xmlChar *)"compressed_size", (const xmlChar *)csize.c_str());
	xmlNewTextChild(_packageXMLNode, NULL, (const xmlChar *)"installed_size", (const xmlChar *)isize.c_str());
	return 0;
}
Example #20
0
xmlNodePtr
gnc_transaction_dom_tree_create(Transaction *trn)
{
    xmlNodePtr ret;
    gchar *str = NULL;

    ret = xmlNewNode(NULL, BAD_CAST "gnc:transaction");

    xmlSetProp(ret, BAD_CAST "version",
	       BAD_CAST transaction_version_string);

    xmlAddChild(ret, guid_to_dom_tree("trn:id", xaccTransGetGUID(trn)));

    xmlAddChild(ret, commodity_ref_to_dom_tree("trn:currency",
                xaccTransGetCurrency(trn)));
    str = g_strdup (xaccTransGetNum(trn));
    if (str && (g_strcmp0(str, "") != 0))
    {
        xmlNewTextChild(ret, NULL, BAD_CAST "trn:num",
			checked_char_cast (str));
    }
    g_free (str);

    add_timespec(ret, "trn:date-posted", xaccTransRetDatePostedTS(trn), TRUE);

    add_timespec(ret, "trn:date-entered",
                 xaccTransRetDateEnteredTS(trn), TRUE);

    str = g_strdup (xaccTransGetDescription(trn));
    if (str)
    {
        xmlNewTextChild(ret, NULL, BAD_CAST "trn:description",
                        checked_char_cast (str));
    }
    g_free (str);

    {
        xmlNodePtr kvpnode = kvp_frame_to_dom_tree("trn:slots",
                             xaccTransGetSlots(trn));
        if (kvpnode)
        {
            xmlAddChild(ret, kvpnode);
        }
    }

    add_trans_splits(ret, trn);

    return ret;
}
Example #21
0
void oval_sysent_to_dom(struct oval_sysent *sysent, xmlDoc * doc, xmlNode * parent)
{
	struct oval_record_field_iterator *rf_itr;
	xmlNsPtr ent_ns = parent->ns;
	xmlNodePtr root_node = xmlDocGetRootElement(doc);
	xmlNode *sysent_tag = NULL;

	char *tagname = oval_sysent_get_name(sysent);
	char *content = oval_sysent_get_value(sysent);
	bool mask = oval_sysent_get_mask(sysent);

	/* omit the value in oval_results if mask=true */
	if (mask && !xmlStrcmp(root_node->name, BAD_CAST OVAL_ROOT_ELM_RESULTS)) {
		sysent_tag = xmlNewTextChild(parent, ent_ns, BAD_CAST tagname, BAD_CAST "");
	} else {
		sysent_tag = xmlNewTextChild(parent, ent_ns, BAD_CAST tagname, BAD_CAST content);
	}

	if (mask) {
		xmlNewProp(sysent_tag, BAD_CAST "mask", BAD_CAST "true");
	}

	oval_datatype_t datatype_index = oval_sysent_get_datatype(sysent);
	if (datatype_index != OVAL_DATATYPE_STRING) {
		xmlNewProp(sysent_tag, BAD_CAST "datatype", BAD_CAST oval_datatype_get_text(datatype_index));
	}

	oval_syschar_status_t status_index = oval_sysent_get_status(sysent);
	if (status_index != SYSCHAR_STATUS_EXISTS) {
		xmlNewProp(sysent_tag, BAD_CAST "status", BAD_CAST oval_syschar_status_get_text(status_index));
	}

	rf_itr = oval_sysent_get_record_fields(sysent);
	if (oval_record_field_iterator_has_more(rf_itr)) {
		xmlNsPtr field_ns = xmlSearchNsByHref(doc, xmlDocGetRootElement(doc), OVAL_SYSCHAR_NAMESPACE);
		if (field_ns == NULL) {
			field_ns = xmlNewNs(xmlDocGetRootElement(doc), OVAL_SYSCHAR_NAMESPACE, NULL);
		}

		while (oval_record_field_iterator_has_more(rf_itr)) {
			struct oval_record_field *rf;

			rf = oval_record_field_iterator_next(rf_itr);
			oval_record_field_to_dom(rf, mask, doc, sysent_tag, field_ns);
		}
	}
	oval_record_field_iterator_free(rf_itr);
}
Example #22
0
PKI_CONFIG_ELEMENT *PKI_CONFIG_ELEMENT_add_child ( PKI_CONFIG *doc, 
			PKI_CONFIG_ELEMENT *node, char *name, char *value ) {

	PKI_CONFIG_ELEMENT *ret = NULL;

	// PKI_log_debug ( "add_child():: name=%s, value=%s", name, value );

	if(!node || !name ) return NULL;

	// snprintf(buf, sizeof(buf), "%s:%s", PKI_NAMESPACE_PREFIX, name );
	// ns = xmlNewNs ( node, NULL, PKI_NAMESPACE_PREFIX);

	// PKI_log_debug ( "add_child():: New Name::%s", name);

	if((ret = xmlNewTextChild( node, NULL, BAD_CAST name, BAD_CAST value ))
								== NULL ) {
		// PKI_log_debug("add_child()::Failed!");
	}


	// xmlFreeNs ( ns );

	// if(doc) _pki_update_config( &doc );

	return ( ret );
}
Example #23
0
xmlNodePtr
cr_xmlNewTextChild(xmlNodePtr parent,
                   xmlNsPtr ns,
                   const xmlChar *name,
                   const xmlChar *orig_content)
{
    int free_content = 0;
    xmlChar *content;
    xmlNodePtr child;

    if (!orig_content) {
        content = BAD_CAST "";
    } else if (xmlCheckUTF8(orig_content)) {
        content = (xmlChar *) orig_content;
    } else {
        size_t len = strlen((const char *) orig_content);
        content = malloc(sizeof(xmlChar)*len*2 + 1);
        cr_latin1_to_utf8(orig_content, content);
        free_content = 1;
    }

    child = xmlNewTextChild(parent, ns, name, content);

    if (free_content)
        free(content);

    return child;
}
Example #24
0
/**
 * Retourne un nouveau noeud correspondant à un produit (NULL en cas d'erreur)
 **/
xmlNodePtr creer_produit(const char *reference, const char *intitule, const char *prix) {
    xmlNodePtr noeud_produit;
    xmlNodePtr noeud_intitule;

    // Création du noeud "produit"
    if ((noeud_produit = xmlNewNode(NULL, BAD_CAST "produit")) == NULL) {
        return NULL;
    }
    // Ajout de son attribut "reference"
    if (xmlSetProp(noeud_produit, BAD_CAST "reference", BAD_CAST reference) == NULL) {
        xmlFreeNode(noeud_produit);
        return NULL;
    }
    // Création du noeud intitule
    if ((noeud_intitule = xmlNewNode(NULL, BAD_CAST "intitule")) == NULL) {
        xmlFreeNode(noeud_produit);
        return NULL;
    }
    xmlNodeSetContent(noeud_intitule, BAD_CAST intitule);
    // Ajout du noeud (intitule) à son père (produit)
    if (xmlAddChild(noeud_produit, noeud_intitule) == NULL) {
        xmlFreeNode(noeud_produit);
        xmlFreeNode(noeud_intitule);
        return NULL;
    }
    // Equivalent plus rapide par rapport au noeud intitule
    // Création du noeud "prix" et ajout à son père (produit)
    if (xmlNewTextChild(noeud_produit, NULL, BAD_CAST "prix", BAD_CAST prix) == NULL) {
        xmlFreeNode(noeud_produit);
        return NULL;
    }

    return noeud_produit;
}
Example #25
0
static void
xml_finish(pcmk__output_t *out, crm_exit_t exit_status) {
    xmlNodePtr node;
    char *rc_as_str = NULL;
    char *buf = NULL;
    xml_private_t *priv = out->priv;

    /* If root is NULL, xml_init failed and we are being called from pcmk__output_free
     * in the pcmk__output_new path.
     */
    if (priv->root == NULL) {
        return;
    }

    rc_as_str = crm_itoa(exit_status);

    node = xmlNewTextChild(priv->root, NULL, (pcmkXmlStr) "status",
                           (pcmkXmlStr) crm_exit_str(exit_status));
    xmlSetProp(node, (pcmkXmlStr) "code", (pcmkXmlStr) rc_as_str);

    buf = dump_xml_formatted_with_text(priv->root);
    fprintf(out->dest, "%s", buf);

    free(rc_as_str);
    free(buf);
}
OSyncXMLField *osync_xmlfield_new(OSyncXMLFormat *xmlformat, const char *name, OSyncError **error)
{
  xmlNodePtr node = NULL;
  OSyncXMLField *xmlfield = NULL;
  osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, xmlformat, name, error);
  osync_assert(xmlformat);
  osync_assert(name);
	
  node = xmlNewTextChild(xmlDocGetRootElement(xmlformat->doc), NULL, BAD_CAST name, NULL);
	
  xmlfield = osync_xmlfield_new_node(xmlformat, node, error);
  if(!xmlfield) {
    xmlUnlinkNode(node);
    xmlFreeNode(node);
    osync_trace(TRACE_EXIT_ERROR, "%s: %s" , __func__, osync_error_print(error));
    return NULL;
  }

  /* XMLFormat entry got added - not sure if it is still sorted */
  osync_xmlformat_set_unsorted(xmlformat);

  /* This XMLField has no keys, so it's for sure it's sorted */
  xmlfield->sorted = TRUE;
	
  osync_trace(TRACE_EXIT, "%s: %p", __func__, xmlfield);
  return xmlfield;
}
Example #27
0
void bg_chapter_list_2_xml(gavl_chapter_list_t * list, xmlNodePtr xml_list)
  {
  char * tmp_string;
  int i;
  xmlNodePtr xml_chapter;

  tmp_string = bg_sprintf("%d", list->timescale);
  BG_XML_SET_PROP(xml_list, "timescale", tmp_string);
  free(tmp_string);
  
  xmlAddChild(xml_list, BG_XML_NEW_TEXT("\n"));
  
  for(i = 0; i < list->num_chapters; i++)
    {
    xml_chapter = xmlNewTextChild(xml_list, NULL,
                                  (xmlChar*)CHAPTER_KEY, NULL);
    
    if(list->chapters[i].name)
      BG_XML_SET_PROP(xml_chapter, NAME_KEY, list->chapters[i].name);

    tmp_string = bg_sprintf("%" PRId64, list->chapters[i].time);
    xmlAddChild(xml_chapter, BG_XML_NEW_TEXT(tmp_string));
    free(tmp_string);
    xmlAddChild(xml_list, BG_XML_NEW_TEXT("\n"));
    }
  
  }
static void
sload_write_config(Control *ctrl, xmlNodePtr parent)
{
    xmlNodePtr root;
    char value[10];
    t_sload *sload;

    sload = (t_sload *)ctrl->data;

    root = xmlNewTextChild(parent, NULL, SLOAD_ROOT, NULL);

    g_snprintf(value, 2, "%d", sload->options.use_label);
    xmlSetProp(root, "Use_Label", value);

    g_snprintf(value, 8, "#%02X%02X%02X",
               (guint)sload->options.color.red >> 8,
               (guint)sload->options.color.green >> 8,
               (guint)sload->options.color.blue >> 8);
    xmlSetProp(root, "Color", value);

    if (sload->options.label_text) {
        xmlSetProp(root, "Text", sload->options.label_text);
    }
    else {
        xmlSetProp(root, "Text", DEFAULTTEXT);
    }
}
Example #29
0
static void plugin_write_config (Control * p_poCtrl, xmlNodePtr p_poParent)
	/* Plugin API */
	/* Write plugin configuration into xml file */
{
    struct plugin_t *poPlugin = (plugin_t *) p_poCtrl->data;
    struct param_t *poConf = &(poPlugin->oConf.oParam);
    xmlNodePtr      poRoot;
    char            acBuffer[16];

    TRACE ("plugin_write_config()\n");

    poRoot = xmlNewTextChild (p_poParent, NULL, PLUGIN_NAME, NULL);

    xmlSetProp (poRoot, CONF_CMD, poConf->acCmd);

    sprintf (acBuffer, "%d", poConf->fTitleDisplayed);
    xmlSetProp (poRoot, CONF_USE_LABEL, acBuffer);

    xmlSetProp (poRoot, CONF_LABEL_TEXT, poConf->acTitle);

    sprintf (acBuffer, "%d", poConf->iPeriod_ms);
    xmlSetProp (poRoot, CONF_UPDATE_PERIOD, acBuffer);

    xmlSetProp (poRoot, CONF_FONT, poConf->acFont);
}				/* plugin_write_config() */
Example #30
0
/**
 * Add an entry to the HTML tree for saving.
 *
 * The node must contain a sequence of node_elements in the following order:
 *
 * \param  entry  hotlist entry to add
 * \param  node   node to add li to
 * \return  true on success, false on memory exhaustion
 */
static bool tree_url_save_entry(struct node *entry, xmlNode *node)
{
	xmlNode *li, *a;
	xmlAttr *href;
	const char *text;

	li = xmlNewChild(node, NULL, (const xmlChar *) "li", NULL);
	if (li == NULL)
		return false;


	text = tree_url_node_get_title(entry);
	if (text == NULL)
		return false;
	a = xmlNewTextChild(li, NULL, (const xmlChar *) "a",
			    (const xmlChar *) text);
	if (a == NULL)
		return false;

	text = tree_url_node_get_url(entry);
	if (text == NULL)
		return false;

	href = xmlNewProp(a, (const xmlChar *) "href", (const xmlChar *) text);
	if (href == NULL)
		return false;
	return true;
}