コード例 #1
0
/**
 * init_node
 *
 * @param node
 * @returns 0 on success, !0 otherwise
 */
static int
init_node(struct dr_node *node)
{
	DIR *d;
	struct dirent *de;
	char child_path[DR_PATH_MAX];
	uint32_t my_drc_index;
	int rc;

	if (node->is_owned)
		find_ofdt_dname(node, node->ofdt_path);

	d = opendir(node->ofdt_path);
	if (!d)
		return -1;

	rc = 0;
	while ((de = readdir(d)) != NULL) {
		if ((de->d_type != DT_DIR) || is_dot_dir(de->d_name))
			continue;

		sprintf(child_path, "%s/%s", node->ofdt_path, de->d_name);

		if (get_my_drc_index(child_path, &my_drc_index))
			continue;

		if (node->dev_type == PCI_HP_DEV) {
			if (node->drc_index == my_drc_index) {
				/* Add hotplug children */
				add_child_node(node, child_path);
			}
		} else {
			if (!node->is_owned) {
				if (node->drc_index == my_drc_index) {
					/* Update node path */
					snprintf(node->ofdt_path, DR_PATH_MAX,
						 "%s", child_path);
					node->is_owned = 1;

					/* Populate w/ children */
					rc = init_node(node);
					if (rc)
						break;
				}
			} else {
				/* Add all DR-capable children */
				add_child_node(node, child_path);
			}
		}
	}

	closedir(d);
	return rc;
}
コード例 #2
0
ファイル: CompactTrie.cpp プロジェクト: Orkat/TextMining
void CompactTrie::add_word_aux( CompactTrieNode* node, const char* word, unsigned int frequency )
{
  if ( strlen( word ) == 0 )
    node->frequency_ = frequency;
  else
  {
    CompactTrieNode* child = add_child_node( node, word[0] );
    add_word_aux( child, &word[1], frequency );
  }
}
コード例 #3
0
ファイル: event-i-to-k.c プロジェクト: GNOME/evolution-kolab
static gchar *
i_event_to_xml(const I_event *i_event)
{
	GString *xml_string = g_string_new("");

	xmlNodePtr root_node = NULL;
	xmlDocPtr doc = NULL;
	xmlChar *xml_buf = NULL;
	gchar *return_string = NULL;
	gint buf_size;

	doc = xmlNewDoc(BAD_CAST "1.0");
	root_node = xmlNewNode(NULL, BAD_CAST KLB_EVENT);
	add_property (root_node, "version", "1.0");
	/* xmlNodeSetContent(root_node, BAD_CAST "content"); */
	xmlDocSetRootElement(doc, root_node);

	conv_incidence_i_to_k(root_node, i_event->incidence);

	if (i_event->show_time_as)
		add_child_node(root_node, KLB_EVENT_SHOW_TIME_AS, show_time_as_to_kolab_string(i_event->show_time_as));
	if (i_event->end_date) {
		gchar *end_date_string = date_or_datetime_to_string(i_event->end_date);
		add_child_node(root_node, KLB_EVENT_END_DATE, end_date_string);
		g_free(end_date_string);
	}
	i_kolab_store_get_xml_nodes(i_event->incidence->common, i_event->incidence->common, root_node);

	/* Convert xml to a string */
	xmlDocDumpFormatMemoryEnc(doc, &xml_buf, &buf_size, "UTF-8", 1);
	g_string_append(xml_string, (gchar*) xml_buf);
	/* log_debug("%s", (char *) xmlbuff); */

	/* Free associated memory. */

	xmlFree(xml_buf);
	xmlFreeDoc(doc);

	return_string = g_string_free (xml_string, FALSE);
	return return_string;
}
コード例 #4
0
/**
 * examine_children
 *
 * @param node
 * @param child_path
 * @returns 0 on success, !0 otherwise
 */
static int
examine_child(struct dr_node *node, char *child_path)
{
	uint32_t my_drc_index;
	int used = 0;
	int rc = 0;

	if (get_my_drc_index(child_path, &my_drc_index))
		goto done;

	if (node->dev_type == PCI_HP_DEV) {
		if (node->drc_index == my_drc_index) {
			/* Add hotplug children */
			add_child_node(node, child_path);
			used = 1;
		}
	} else {
		if (! node->is_owned) {
			if (node->drc_index == my_drc_index) {
				/* Update node path */
				snprintf(node->ofdt_path, DR_PATH_MAX, "%s",
					 child_path);
				node->is_owned = 1;
				used = 1;

				/* Populate w/ children */
				rc = init_node(node);
			}
		} else {
			/* Add all DR-capable children */
			add_child_node(node, child_path);
			used = 1;
		}
	}
done:
	if (! used)
		free(child_path);

	return rc;
}
コード例 #5
0
ファイル: kolab-util.c プロジェクト: GNOME/evolution-kolab
/*
 * converts a GList of strings to xml nodes with the same name below one node
 */
void convert_GList_String_to_xmlNodes (GList *string_list, char* node_name, xmlNodePtr node)
{
	GList *iterator;
	iterator = string_list;

	while(iterator != NULL){
		gchar *element = ((gchar*)string_list->data);

		add_child_node(node, node_name, element);

		iterator = iterator->next;
	}
	g_list_free(iterator);
}
コード例 #6
0
ファイル: agcsxmlcldes.c プロジェクト: jskelin/AGCS
/**
 * This is a key function that builds the AGCS XML object representation tree. It is implemented so that it can build a tree
 * for only those XML input files for the AGCS that are of the "cldes" format but because of the intelligently implemented
 * various "internal" functions of the AGCS XML Parser it is easily possible to expand it's functionality so that it can accept
 * different/other XML format files too.
 *
 *	\param[in]		sourceFileName		The name of the input file containing class descriptions.
 *
 * 	\return			enum ret__build_xml_cldes_tree
 *
 * \author Antonio Poscic [email protected]
 * \date 2008-05-06
 */
enum ret__build_xml_cldes_tree build_xml_cldes_tree (char* sourceFileName)
{
	FILE* inputFile;
	
	/**
	 * We need some helper nodes and node pointers to create the tree.
	 */
	agcsXMLClDesNode tempNode;
	agcsXMLClDesNodePtr primaryNode, secondaryNode;
	
	/**
	 * Variable that is used to signal if the primary node is completed.
	 * This is because we assume at most two levels of nodes below the root node,
	 * it is possible to easily implement a recursive function that would deal with as many
	 * node levels as needed. This is redundant at this point as the AGCS Class Description
	 * XML has at most two levels of nodes.
	 */
	unsigned char primaryNodeComplete = 0;
	
	/**
	 * Some more helper variables and string, tempAttribute is used to hold the attributes
	 * prior to adding to the attribute list and temporaryNodeName holds the node name.
	 */
	/* nodeAttribute tempAttribute; */

	char temporaryNodeName[NODE_NAME_MAX_LENGTH];
	
	/**
	 * Check if the source filename is valid.
	 */
	if (sourceFileName == NULL)
		return (RET__BUILD_XML_CLDES_TREE__INPUT_FILE_ERROR);
	
	/**
	 * Try to open the input file with class descriptions. If it fails, notify the caller function.
	 */
	inputFile = fopen (sourceFileName, "r");
	
	if (inputFile == NULL)
		return (RET__BUILD_XML_CLDES_TREE__INPUT_FILE_ERROR);
	
	/**
	 * Make sure that a prior XML tree representation does not exist.
	 */
	destroy_xml_cldes_tree ();
	
	/**
	 * Set the root node to NULL.
	 */
	rootNode = NULL;
	
	/**
	 * Read the root node and return appropriate value if it fails to read the node.
	 */
	switch (read_xml_tag (inputFile, &tempNode, temporaryNodeName)) {
		case RET__READ_XML_TAG__END_OF_FILE:
			return (RET__BUILD_XML_CLDES_TREE__MALFORMED_XML);
		case RET__READ_XML_TAG__FILE_READ_ERROR:
			return (RET__BUILD_XML_CLDES_TREE__INPUT_FILE_ERROR);
		case RET__READ_XML_TAG__MALFORMED_XML:
		case RET__READ_XML_TAG__FAILURE:
		case RET__READ_XML_TAG__CLOSED_TAG:
			return (RET__BUILD_XML_CLDES_TREE__MALFORMED_XML);
		case RET__READ_XML_TAG__OPENED_TAG:
			break;
		default:
			return (RET__BUILD_XML_CLDES_TREE__FAILED);
	}
	
	/**
	 * Make the node that was just read the root node. If this function fails return
	 * an appropriate value, for example, MEMORY_ERROR if the create_root_element
	 * function reported a memory error.
	 */
	switch (create_root_element (tempNode)) {
		case RET__CREATE_ROOT_ELEMENT__FAILED:
			return (RET__BUILD_XML_CLDES_TREE__FAILED);
		case RET__CREATE_ROOT_ELEMENT__MEMORY_ERROR:
			return (RET__BUILD_XML_CLDES_TREE__MEMORY_ERROR);
		case RET__CREATE_ROOT_ELEMENT__FAULTY_NODE:
			return (RET__BUILD_XML_CLDES_TREE__FAILED);
		case RET__CREATE_ROOT_ELEMENT__SUCCESS:
			break;
		default:
			return (RET__BUILD_XML_CLDES_TREE__FAILED);
	}
	
	/**
	 * This is the main loop in this function. It reads XML tags and creates nodes in the tree while
	 * the end of the file is not reached.
	 */
	while (1) {
	
		/**
		 * Read a single XML tag.
		 */
		switch (read_xml_tag (inputFile, &tempNode, temporaryNodeName)) {
			
			/**
			 * If it is an open tag, assume it has children and read tags that should be added as children of the
			 * node signaled with the opened tag.
			 */
			case RET__READ_XML_TAG__OPENED_TAG:
				
				/**
				 * This is indeed a primary node/a direct child of the root node. Allocate memory for
				 * the new node and add the node to the root node.
				 */
				primaryNode = NULL;
				primaryNode = malloc (sizeof (agcsXMLClDesNode));
				*primaryNode = tempNode;
				add_child_node (rootNode, primaryNode);
				
				primaryNodeComplete = 0;
				
				/**
				 * This loops reads tags that form the current primary node's children.
				 */
				while (1) {
				
					switch (read_xml_tag (inputFile, &tempNode, temporaryNodeName)) {
					
						/**
						 * While the read_xml_tag function returns SUCCESS it means that a single-line tag was read
						 * that announces a child node of the primary node. We add this node to the recent/current primary
						 * node.
						 */
						case RET__READ_XML_TAG__SUCCESS:
							secondaryNode = NULL;
							secondaryNode = malloc (sizeof (agcsXMLClDesNode));
							*secondaryNode = tempNode;
							add_child_node (primaryNode, secondaryNode);
							break;
					
						/**
						 * We check if the read tag is a closing tag. If it is, it marks that we have reached the closing tag of
						 * the current primary node. We check if this is indeed the closing tag of the last read primary node.
						 * If it is not the expected closing tag we notify the caller function that the XML is malformed.
						 * We use the primaryNodeComplete variable to jump out of the loop.
						 */
						case RET__READ_XML_TAG__CLOSED_TAG:
							if (strcmp (tempNode.nodeName, primaryNode->nodeName) == 0) {
								primaryNodeComplete = 1;
								break;
							}
							else
								return (RET__BUILD_XML_CLDES_TREE__MALFORMED_XML);
						default:	
							return (RET__BUILD_XML_CLDES_TREE__MALFORMED_XML);
					}
					
					if (primaryNodeComplete)
						break;
					
				}
				
				break;
			
			/**
			 * This should only occur if we have reached the closing tag of the root node.
			 * If it is not the root node it means that the XML is not AGCS Class Description compliant.
			 */
			case RET__READ_XML_TAG__CLOSED_TAG:
				if (strcmp (temporaryNodeName, "prog") == 0)
					continue;
				else
					return (RET__BUILD_XML_CLDES_TREE__MALFORMED_XML);
				break;
			
			/**
			 * Returns in case of end of file (returns SUCCESS, all nodes have been successfully read), 
			 * file read error (FILE_READ_ERROR, returns INPUT_FILE_ERROR, signaling a problem
			 * with the input file), malformed XML and generic failure (MALFORMED_XML, FAILURE, returns
			 * MALFORMED_XML because there was an expected syntax exception in the XML file).
			 * By default it returns that the formation of the tree failed for unknown reasons.
			 */
			case RET__READ_XML_TAG__END_OF_FILE:
				fclose (inputFile);
				return (RET__BUILD_XML_CLDES_TREE__SUCCESS);
			
			case RET__READ_XML_TAG__FILE_READ_ERROR:
				return (RET__BUILD_XML_CLDES_TREE__INPUT_FILE_ERROR);
			
			case RET__READ_XML_TAG__MALFORMED_XML:
			case RET__READ_XML_TAG__FAILURE:
				return ((RET__BUILD_XML_CLDES_TREE__MALFORMED_XML));
			
			default:
				return (RET__BUILD_XML_CLDES_TREE__FAILED);
		}
	}
	
	/**
	 * We close the input file.
	 */
	fclose (inputFile);
	
}
コード例 #7
0
/**
 * Convert I_common to kolab XML xmlNodePtr
 */
void
common_i_to_k(xmlNodePtr root_node, I_common *i_common)
{
	GList *lsl = NULL;

	if (i_common == NULL)
		return;
	/* Construct children of root node. */
	add_child_node(root_node, KLB_CMN_PRODUCT_ID, KOLABCONV_PRODUCT_ID);
	g_assert(i_common->uid);
	add_child_node(root_node, KLB_CMN_UID, i_common->uid->str );
	if(i_common->body)
		add_child_node(root_node, KLB_CMN_BODY, i_common->body->str);
	if(i_common->categories)
		add_child_node(root_node, KLB_CMN_CATEGORIES, i_common->categories->str);
	if(i_common->creation_datetime) {
		gchar *creation_string = date_or_datetime_to_string(i_common->creation_datetime);
		add_child_node(root_node, KLB_CMN_CREATION_DATE, creation_string);
		g_free(creation_string);
	}
	if(i_common->last_modified_datetime) {
		gchar *modified_string = date_or_datetime_to_string(i_common->last_modified_datetime);
		add_child_node(root_node, KLB_CMN_LAST_MODIFICATION_DATE, modified_string);
		g_free(modified_string);
	}
	if(i_common->sensitivity)
		if (i_common->sensitivity != ICOMMON_SENSITIVITY_NULL)	/* if its ICOMMON_SENSITIVITY_NULL it is either in kolab store or has never been there */
			add_child_node(root_node, KLB_CMN_SENSITIVITY, sensitivity_i_to_k(i_common->sensitivity));
	if(i_common->vtimezone)
		add_child_node(root_node, KLB_CMN_VTIMEZONE, i_common->vtimezone);
	if(i_common->is_html_richtext)
		add_child_node(root_node, KLBX_CMN_RICHTEXT, i_common->is_html_richtext == TRUE ? "true" : "false" );
	/* add link attachments to the kolab xml */
	lsl = i_common->link_attachments;
	for (; lsl; lsl=lsl->next)
		add_child_node(root_node, KLB_CMN_LINK_ATTACHMENT, (gchar*)lsl->data);
	/* add inline attachment names to the kolab xml */
	lsl = i_common->inline_attachment_names;
	for (; lsl; lsl=lsl->next)
		add_child_node(root_node, KLB_CMN_INLINE_ATTACHMENT, (gchar*)lsl->data);

	k_evo_store_add_all(i_common, root_node);
}
コード例 #8
0
ファイル: misc.c プロジェクト: yeslogic/prince-html
/*-----------------------------------------------------------------*/
void add_child_to_foster_parent(element_stack *o_e_st, node *child_node)
{
	element_node *temp_element;
	element_stack *temp_stack = o_e_st;

	assert(child_node != NULL);
	
	while(temp_stack != NULL)
	{
		temp_element = open_element_stack_top(temp_stack);

		if(strcmp(temp_element->name, "table") == 0)
		{
			if(child_node->type == TEXT_N)
			{
				if((temp_element->previous_sibling != NULL) && 
				   (temp_element->previous_sibling->type == TEXT_N))
				{
					int len;
					unsigned char *str1;
					text_node *t1 = (text_node *)temp_element->previous_sibling;
					text_node *t2 = (text_node *)child_node;

					str1 = t1->text_data;

					len = strlen(t1->text_data) + strlen(t2->text_data);	//text_data is never NULL.

					t1->text_data = malloc(len + 1);

					t1->text_data = strcpy(t1->text_data, str1);
					t1->text_data = strcat(t1->text_data, t2->text_data);
	
					free(str1);
					free_node(child_node);
				}
				else
				{
					insert_child_node(temp_element->parent, child_node, (node *)temp_element);
				}
			}
			else if(child_node->type == ELEMENT_N)
			{
				insert_child_node(temp_element->parent, child_node, (node *)temp_element);
			}
			else
			{
				;
			}
			break;
		}
		else if(strcmp(temp_element->name, "html") == 0)
		{
			add_child_node(temp_element, child_node);
			break;
		}
		else
		{
			temp_stack = previous_stack_node(temp_stack);
		}
	}
}