コード例 #1
0
ファイル: xml_tool.cpp プロジェクト: klampworks/mammon
int main(int argc, char **argv)
{
    assert(argv[1]); 
    std::ifstream t(argv[1]);
    std::string str((std::istreambuf_iterator<char>(t)),
        std::istreambuf_iterator<char>());

    //tidy::tidy(str);
	//xmlDocPtr doc = htmlParseFile(f_doc, NULL);
	xmlDocPtr doc = htmlParseDoc(BAD_CAST str.c_str(), NULL);
	if (!doc) {
		printf("libxml failed to parse file <%s>\n", argv[1]);
		return 1;
	}

	xmlNode *doc_head = xmlDocGetRootElement(doc);
    if (argc < 3) {
        print_element_names(doc_head, 0);
    } else {
        run_xpath(doc, argv[2]);
    } 

	//xmlFree(doc_head);
	return 0;
}
コード例 #2
0
ファイル: xml_tool.cpp プロジェクト: klampworks/mammon
int run_xpath(xmlDoc *doc, const char *xpath)
{
	xmlXPathContext *xpath_ctx = xmlXPathNewContext(doc);
	if (!xpath_ctx) {
		printf("Could not create new xpath context.\n");
		//xmlFreeDoc(doc);
		return 1;
	}

	xmlChar *xml_xpath = xmlCharStrdup(xpath);
	xmlXPathObject *xpath_obj = xmlXPathEvalExpression(xml_xpath, xpath_ctx);
	if (!xpath_obj) {
		puts("Could not evaluate xpath expression.\n");
		free(xml_xpath);
		return 1;
	}

    assert(xpath_obj->nodesetval->nodeTab);
    for (auto n = *xpath_obj->nodesetval->nodeTab; n; n = n->next) {
        printf("----------------------------------------"
                "----------------------------------------\n");
        print_element_names(n, 0);
        printf("----------------------------------------"
                "----------------------------------------\n");
    }

	//xmlXPathFreeObject(xpath_obj);
	free(xml_xpath);

	//xmlXPathFreeContext(xpath_ctx); 
	//xmlFreeDoc(doc);
	return 0;
}
コード例 #3
0
ファイル: of-config1.1.1.c プロジェクト: bisdn/of-config
/* !DO NOT ALTER FUNCTION SIGNATURE! */
int callback_ofc_capable_switch_ofc_logical_switches (void ** data, XMLDIFF_OP op, xmlNodePtr node, struct nc_err** error)
{
	nc_verb_verbose("%s: data=%p, op=%d\n", __PRETTY_FUNCTION__, data, op);
	print_element_names(node, 0);

	int rv = EXIT_SUCCESS;
	if (NULL != node->children) {

		assert(ofc_state.lsi_list);
		assert(XMLDIFF_CHAIN & op);

		if ((XMLDIFF_ADD|XMLDIFF_REM|XMLDIFF_MOD|XMLDIFF_CHAIN) & op) {

			struct lsi *current_lsi;
			while ( (current_lsi = list_next(ofc_state.lsi_list)) ) {
				handle_ports(current_lsi->res.port_list_del);
			}

			while ( (current_lsi = list_pop_head(ofc_state.lsi_list)) ) {
				handle_ports(current_lsi->res.port_list_add);
				lsi_cleanup(current_lsi);
			}

		} else {
			nc_verb_error("unsupported op");
			assert(0);
		}

		list_delete(ofc_state.lsi_list);
		ofc_state.lsi_list = NULL;
	}

	return rv;
}
コード例 #4
0
ファイル: News.c プロジェクト: whoo/Meteo
static void print_element_names(xmlNode * a_node)
{
	xmlNode *cur_node = NULL,*cur;
	char *key;
	char *name;
	char tb[128];

	for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
		if (cur_node->type == XML_ELEMENT_NODE) {
			if (!xmlStrcmp(cur_node->name,(const xmlChar *)"item"))
			{
				cur=cur_node;
				for (cur=cur_node->children;cur;cur=cur->next)
				{
/*					if (!xmlStrcmp(cur->name,(const xmlChar *)"category")&&cur->children)
						printf("[%s]",cur->children->content);*/
					if (!xmlStrcmp(cur->name,(const xmlChar *)"title")&&cur->children)
						{
						//printf("%s\n",(cur->children->content));
						
						strcpy(tb,cur->children->content);
						printf("%s\n",Supper(cur->children->content));
						}
				}
			}
		}
		print_element_names(cur_node->children);
	}
}
コード例 #5
0
ファイル: of-config1.1.1.c プロジェクト: bisdn/of-config
/* !DO NOT ALTER FUNCTION SIGNATURE! */
int callback_ofc_capable_switch_ofc_logical_switches_ofc_switch_ofc_controllers_ofc_controller (void ** data, XMLDIFF_OP op, xmlNodePtr node, struct nc_err** error)
{
	nc_verb_verbose("%s: data=%p, op=%d\n", __PRETTY_FUNCTION__, data, op);
	print_element_names(node, 0);

	if (NULL == *data) {
		*data = calloc(1, sizeof(struct lsi));
		assert(*data);
	}

	if ((XMLDIFF_ADD) & op) {
		if (NULL == LSI(data)->controller_list_add) {
			LSI(data)->controller_list_add = list_new();
			assert(LSI(data)->controller_list_add);
		}

		list_append_data(LSI(data)->controller_list_add, __data);
		__data = NULL;

	} else if ((XMLDIFF_REM) & op) {
		if (NULL == LSI(data)->controller_list_del) {
			LSI(data)->controller_list_del = list_new();
			assert(LSI(data)->controller_list_del);
		}

		list_append_data(LSI(data)->controller_list_del, __data);
		__data = NULL;
	} else {
		nc_verb_error("not implemented");
		assert(0);
	}

	return EXIT_SUCCESS;
}
コード例 #6
0
ファイル: main_xml.c プロジェクト: davidcl/reqflow
int main(int argc, char **argv)
{
    LIBXML_TEST_VERSION
    char           *filename;

    if (argc < 2) {
        fprintf(stderr, "Usage: %s filename.xml\n", argv[0]);
        return 1;
    }
    filename = argv[1];

    xmlDocPtr         document;
    xmlNode        *root, *first_child, *node;

    document = xmlReadFile(filename, NULL, 0);
    root = xmlDocGetRootElement(document);

    print_element_names(document, root);

    fprintf(stdout, "Root is <%s> (%i)\n", root->name, root->type);
    first_child = root->children;
    for (node = first_child; node; node = node->next) {
        fprintf(stdout, "\t Child is <%s> (%i)\n", node->name, node->type);
    }
    fprintf(stdout, "...\n");
    return 0;
}
コード例 #7
0
ファイル: xml_tool.cpp プロジェクト: klampworks/mammon
void print_element_names(xmlNode *a_node, int indent)
{
	xmlNode *cur_node = NULL;

	for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
		if (cur_node->type == XML_ELEMENT_NODE) {
            for (int i = 0; i < indent; ++i)
                printf(".");

			//printf("node type: Element, name: %s\n", cur_node->name);
            if (xmlStrEqual(BAD_CAST "br", cur_node->name))
                continue;

            printf("<%s", cur_node->name);
            for (auto a = cur_node->properties; a; a = a->next) {
                printf(" ");
                printf("%s", a->name);
                for (auto b = a->children; b; b = b->next) {
                    auto t = xmlNodeGetContent(b);
                    printf("='%s'", t);
                    free(t);
                }
            }
            printf(">\n");
		}

		print_element_names(cur_node->children, indent+1);
		if (cur_node->type != XML_TEXT_NODE && cur_node->name) {
            for (int i = 0; i < indent; ++i)
                printf(".");
            printf("</%s>\n", cur_node->name);
        }
	}
}
コード例 #8
0
ファイル: of-config1.1.1.c プロジェクト: bisdn/of-config
/* !DO NOT ALTER FUNCTION SIGNATURE! */
int callback_ofc_capable_switch_xdpd_mgmt_cross_connections_xdpd_mgmt_cross_connection (void ** data, XMLDIFF_OP op, xmlNodePtr node, struct nc_err** error)
{
	nc_verb_verbose("%s: data=%p, op=%d\n", __PRETTY_FUNCTION__, data, op);
	print_element_names(node, 0);

	uint64_t dpid_1 = 0;
	uint64_t dpid_2 = 0;
	uint64_t port_no1 = 0;
	uint64_t port_no2 = 0;

	if (XMLDIFF_ADD & op) {
		int i=0;
		xmlNodePtr lsi;
		for (lsi = node->children->next; NULL != lsi; lsi = lsi->next, ++i) {
			assert(xmlStrEqual(lsi->name, BAD_CAST "switch"));

			// resolve dpid
			char buf[255];
			xmlStrPrintf(buf, sizeof(buf), "/ofc:capable-switch/ofc:logical-switches/ofc:switch[ofc:id='%s']", XML_GET_CONTENT(lsi->children->children));
			xmlXPathObjectPtr xpath_obj_ptr = get_node(lsi->doc, namespace_mapping, buf);
			assert(xpath_obj_ptr);
			assert(xpath_obj_ptr->nodesetval);


			// there can only be one lsi with this id
			if (1 == xpath_obj_ptr->nodesetval->nodeNr) {

				xmlNodePtr dpid_node = find_element(BAD_CAST "datapath-id", xpath_obj_ptr->nodesetval->nodeTab[0]->children);
				assert(dpid_node);

				if (0 == i) {
					dpid_1 = parse_dpid(XML_GET_CONTENT(dpid_node->children));
				} else {
					dpid_2 = parse_dpid(XML_GET_CONTENT(dpid_node->children));
				}

			} else {
				// otherwise something is really screwed
				assert(0);
			}
			xmlXPathFreeObject(xpath_obj_ptr);

			xmlNodePtr requested_portnum = find_element(BAD_CAST "requested-of-port-number", lsi->children);
			if (NULL != requested_portnum) {

				if (0 == i) {
					port_no1 = strtoul(XML_GET_CONTENT(requested_portnum->children), NULL, 10);
				} else {
					port_no2 = strtoul(XML_GET_CONTENT(requested_portnum->children), NULL, 10);
				}
			}
		}

		nc_verb_verbose("dpid_1 = %lx, dpid_2 = %lx\n", dpid_1, dpid_2);
		lsi_cross_connect(ofc_state.xmp_client_handle, dpid_1, port_no1, dpid_2, port_no2);
	}

	return EXIT_SUCCESS;
}
コード例 #9
0
static void print_element_names(xmlNode * a_node)
{
    xmlNode *cur_node = NULL;

    for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
        if (cur_node->type == XML_ELEMENT_NODE) {
            printf("node type: Element, name: %s\n", cur_node->name);
        }

        print_element_names(cur_node->children);
    }
}
コード例 #10
0
void
karakter_betoltes(gchar *filenev)
{
	xmlDocPtr doc;
	xmlNode *root;

	doc = xmlReadFile(filenev, "UTF-8", 0);

	root = xmlDocGetRootElement(doc);
	print_element_names(root, root);

	xmlFreeDoc(doc);
}
コード例 #11
0
 static void
 print_element_names(xmlNode * a_node, std::string indentation)
 {
     xmlNode *cur_node(0);
     for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
         if (cur_node->type == XML_ELEMENT_NODE) {
             printf("%snode type: Element, name: %s\n", indentation.c_str(), cur_node->name);
         } else if (cur_node->type == XML_TEXT_NODE) {
             printf("%snode type: Text, content: %s(%lu)\n", indentation.c_str(), cur_node->content, strlen((const char *)cur_node->content));
         }
         print_element_names(cur_node->children, indentation+"\t");
     }
 }
コード例 #12
0
ファイル: tree1.c プロジェクト: JacobStoren/ert
/**
 * print_element_names:
 * @a_node: the initial xml node to consider.
 *
 * Prints the names of the all the xml elements
 * that are siblings or children of a given xml node.
 */
static void print_element_names(xmlNode * a_node, char *str) {
    xmlNode *cur_node = NULL;
    char level[100];
    sprintf(level, "%s-", str);
    //strcat(level, str);

    for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
        if (cur_node->type == XML_ELEMENT_NODE) {
            printf("%s node type: Element, name: %s\n", level, cur_node->name);
        }

        print_element_names(cur_node->children, level);
    }
}
コード例 #13
0
ファイル: News.c プロジェクト: whoo/Meteo
void parsxml(struct MemoryStruct *document)
{
	xmlDocPtr doc;
	xmlNodePtr cur;
	char *key;

	doc=xmlParseMemory(document->memory,document->size);
	cur=xmlDocGetRootElement(doc);
	print_element_names(cur->children);

	xmlMemoryDump();

	xmlFreeDoc(doc);
	xmlCleanupParser();
}
コード例 #14
0
ファイル: of-config1.1.1.c プロジェクト: bisdn/of-config
/* !DO NOT ALTER FUNCTION SIGNATURE! */
int callback_ofc_capable_switch_ofc_resources_ofc_port_ofc_configuration_ofc_admin_state (void ** data, XMLDIFF_OP op, xmlNodePtr node, struct nc_err** error)
{
	nc_verb_verbose("%s: data=%p, op=%d\n", __PRETTY_FUNCTION__, data, op);
	print_element_names(node, 0);

	int rv = EXIT_SUCCESS;
	int down = 0;	// default is up

	if ((XMLDIFF_ADD|XMLDIFF_MOD) & op) {

		if (xmlStrEqual(XML_GET_CONTENT(node->children), BAD_CAST "down")) {
			down = 1;
		}

		// sanity check... if the content is not "down", it has to be "up"
		assert(down || xmlStrEqual(XML_GET_CONTENT(node->children), BAD_CAST "up"));

		// currently the resource-id is the port name (even if the name is not set
		xmlNodePtr tmp = find_element(BAD_CAST "resource-id",  node->parent->parent->children);
		assert(tmp);

		if (down) {
			// set interface down
			nc_verb_verbose("set interface %s down\n", tmp->children->content);
			if (port_disable(ofc_state.xmp_client_handle, tmp->children->content)) {
				rv = EXIT_FAILURE;
			}

		} else {
			// set interface up
			nc_verb_verbose("set interface %s up\n", tmp->children->content);
			if (port_enable(ofc_state.xmp_client_handle, tmp->children->content)) {
				rv = EXIT_FAILURE;
			}
		}

	} else if (XMLDIFF_REM & op) {
		// setting interface up
	} else {
		nc_verb_error("unsupported op");
		assert(0);
	}


	return rv;
}
コード例 #15
0
ファイル: main_xml.c プロジェクト: davidcl/reqflow
/**
 * print_element_names:
 * @a_node: the initial xml node to consider.
 *
 * Prints the names of the all the xml elements
 * that are siblings or children of a given xml node.
 */
static void print_element_names(xmlDocPtr doc, xmlNode * a_node)
{
    xmlNode *cur_node = NULL;

    for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
        if (cur_node->type == XML_ELEMENT_NODE) {
            printf("node type: Element, name: %s\n", cur_node->name);
        } else if (XML_TEXT_NODE == cur_node->type) {
            xmlChar *key;
            //key = xmlNodeListGetString(doc, cur_node, 1);
            key = xmlNodeListGetRawString(doc, cur_node, 1);
            printf("text node: %s\n", key);
            xmlFree(key);
        }

        print_element_names(doc, cur_node->children);
    }
}
コード例 #16
0
static void
print_element_names(xmlNode *root, xmlNode * a_node)
{
    xmlNode *cur_node = NULL;

    for (cur_node = a_node; cur_node; cur_node = cur_node->next)
	{
        if (cur_node->type == XML_ELEMENT_NODE)
		{
			gchar *path;
			xmlNode *a;
			gint len = 1;
			xmlNode *last, *prev;

			for (a = cur_node; a; a = a->parent)
				if (a->name != NULL)
					len += 1 + strlen((gchar *)a->name);

			path = g_malloc(len);
			memset(path, 0, len);

			last = prev = root;

			while (last != cur_node)
				for (a = cur_node; a != root->parent; a = a->parent)
				{
					if (last == a)
					{
						strcat(path, "/");
						strcat(path, (gchar *)a->name);
						last = prev;
					}
					prev = a;
				}
			strcat(path, "/");
			strcat(path, (gchar *)cur_node->name);

			printf("len: %d; path: %s\n", len, path);
			//printf("node type: Element, name: %s, parent: %s\n", cur_node->name, cur_node->parent->name);
		}

        print_element_names(root, cur_node->children);
    }
}
コード例 #17
0
ファイル: parse_xml.c プロジェクト: davidmerrick/Classes
/**
 * Simple example to parse a file called "file.xml", 
 * walk down the DOM, and print the name of the 
 * xml elements nodes.
 */
int
main(int argc, char **argv)
{
    xmlDoc *doc = NULL;
    xmlNode *root_element = NULL;
/*
    if (argc != 2)
        return(1);
*/
    /*
     * this initialize the library and check potential ABI mismatches
     * between the version it was compiled for and the actual shared
     * library used.
     */
    LIBXML_TEST_VERSION

    /*parse the file and get the DOM */
    doc = xmlReadMemory("<request type=\"hello\"><item name=\"world\"/></request>", strlen("<request type=\"hello\"><item name=\"world\"/></request>"), "noname.xml", NULL, 0);

    if (doc == NULL) {
        printf("error: could not parse file %s\n", argv[1]);
    }

    /*Get the root element node */
    root_element = xmlDocGetRootElement(doc);
	
	printf("Root element type = %s\n", xmlGetProp(root_element, "type"));
	
    print_element_names(root_element);

    /*free the document */
    xmlFreeDoc(doc);

    /*
     *Free the global variables that may
     *have been allocated by the parser.
     */
    xmlCleanupParser();

    return 0;
}
コード例 #18
0
ファイル: tspcfg_file_main.c プロジェクト: deweerdt/TSP
/**
 * print_element_names:
 * @param[in] a_node the initial xml node to consider.
 *
 * Prints the names of the all the xml elements
 * that are siblings or children of a given xml node.
 */
static void
print_element_names(xmlNode * a_node)
{
    xmlNode *cur_node = NULL;
    xmlChar * donne;

    for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
        if (cur_node->type == XML_ELEMENT_NODE) {
            printf("node type: Element, name: %s\n", cur_node->name);
	    
	    if(!(strcmp((char*)cur_node->name,"TSP_providers")))
	    {
	      donne=xmlGetProp(cur_node,(unsigned char*)"name");
	      printf("donne: %s\n",donne);
	    }

        }

        print_element_names(cur_node->children);
    }
}
コード例 #19
0
ファイル: test_example2.c プロジェクト: beku/SimpleUI
/**
 * Simple example to parse a file called "file.xml", 
 * walk down the DOM, and print the name of the 
 * xml elements nodes.
 */
int
main(int argc, char **argv)
{
    xmlDoc *doc = NULL;
    xmlNode *root_element = NULL;

    if (argc != 2)
        return(1);

    /*
     * this initialize the library and check potential ABI mismatches
     * between the version it was compiled for and the actual shared
     * library used.
     */
    LIBXML_TEST_VERSION

    /*parse the file and get the DOM */
    doc = xmlReadFile(argv[1], NULL, 0);

    if (doc == NULL) {
        printf("error: could not parse file %s\n", argv[1]);
    }

    /*Get the root element node */
    root_element = xmlDocGetRootElement(doc);

    print_element_names(root_element);

    /*free the document */
    xmlFreeDoc(doc);

    /*
     *Free the global variables that may
     *have been allocated by the parser.
     */
    xmlCleanupParser();

    return 0;
}
コード例 #20
0
int main(int argc, char **argv)
{
    xmlDoc *doc = NULL;
    xmlNode *root_element = NULL;

    LIBXML_TEST_VERSION

    doc = xmlReadFile("libxml2.xml", NULL, 0);

    if (doc == NULL)
    {
        printf("error: could not parse file %s\n", "libxml2.xml");
        return 0;
    }

    root_element = xmlDocGetRootElement(doc);
    print_element_names(root_element);

    xmlFreeDoc(doc);
    xmlCleanupParser();

    return 0;
}
コード例 #21
0
ファイル: client.c プロジェクト: Gaoithe/openimscore_ims
/* Check if the response is an error, redirect response
 * or it includes a warning
 * @param response - the LoST response body
 * @param resp_type - the response type: ERROR, REDIRECT, WARNING or OK
 * @returns the root node of the parsed xml body
 */ 
xmlNode* get_LoST_resp_type(str response, lost_resp_type * resp_type, str * reason){
			
	xmlNode * root, * node, * child;

	reason->s = NULL;
	reason->len = 0;

	root = xml_parse_string(response);
	if(!root)
		return root;

#ifdef LOST_DEBUG	
	print_element_names(root);
#endif

	if(strcmp((char*)root->name, LOST_ERR_NODE_NAME) == 0){
		DEBUG_LOG("LoST response has an error response\n");
		
		node = child_node(root);
		if(node){
			DEBUG_LOG("reason %s\n", node->name);
			reason->s = (char*)node->name;
			reason->len = strlen(reason->s);			
#ifdef LOST_DEBUG
			print_attr(node, LOST_MSG_ATTR_NAME);
#endif
		}else {
			DEBUG_LOG("the message has no reason\n");
		}

		*resp_type = LOST_ERR;

	} else if(strcmp((char*)root->name, LOST_REDIR_NODE_NAME) == 0){

		DEBUG_LOG("LoST response has a redirect response\n");
#ifdef LOST_DEBUG		
		print_attr(root, LOST_TGT_ATTR_NAME);
#endif
		*resp_type = LOST_REDIR;

	} else 	if(strcmp((char*)root->name, LOST_FINDSRESP_NODE_NAME) != 0){

		ERROR_LOG("invalid LoST response\n");
		*resp_type = LOST_ERR;

	} else {
		
		node = child_named_node(root, LOST_WRNG_NODE_NAME);
		if(node){
			DEBUG_LOG("LoST response has a response with warning\n");
			if((child = child_node(node))){
				DEBUG_LOG("reason %s\n", child->name);
				reason->s = (char*)child->name;
				reason->len = strlen(reason->s);			
#ifdef LOST_DEBUG
				print_attr(node, LOST_MSG_ATTR_NAME);
#endif
			}else {
				DEBUG_LOG("warning without reason\n");
			}

			*resp_type = LOST_WRNG;
		}else
			*resp_type = LOST_OK;
	}

	return root;
}
コード例 #22
0
ファイル: of-config1.1.1.c プロジェクト: bisdn/of-config
/* !DO NOT ALTER FUNCTION SIGNATURE! */
int callback_ofc_capable_switch_ofc_logical_switches_ofc_switch_ofc_resources_ofc_port (void ** data, XMLDIFF_OP op, xmlNodePtr node, struct nc_err** error)
{
	nc_verb_verbose("%s: data=%p, op=%d\n", __PRETTY_FUNCTION__, data, op);

	print_element_names(node, 0);

	// retrieve the dpid of this twig
	xmlNodePtr tmp = find_element(BAD_CAST "datapath-id",  node->parent->parent->children);
	assert(tmp);
	uint64_t dpid = parse_dpid(tmp->children->content);

	int rv = EXIT_SUCCESS;

	// fixme depending on the erropt (e.g. NC_EDIT_ERROPT_ROLLBACK we might still have *data set)
	assert(data);
	if (NULL == *data) {
		*data = calloc(1, sizeof(struct lsi));
		assert(*data);
	}

	if (XMLDIFF_ADD & op) {

		xmlChar buf[255];
		// check if port is already attached
		xmlStrPrintf(buf, sizeof(buf), "/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:resources/ofc:port[text()='%s']", XML_GET_CONTENT(node->children));
		xmlXPathObjectPtr xpath_obj_ptr = get_node(node->doc, namespace_mapping, buf);
		assert(xpath_obj_ptr);
		assert(xpath_obj_ptr->nodesetval);

		if (1 == xpath_obj_ptr->nodesetval->nodeNr) {

			if (NULL == LSI(data)->res.port_list_add) {
				LSI(data)->res.port_list_add = list_new();
				assert(((struct lsi* )*data)->res.port_list_add);
			}
			struct port *p = calloc(1, sizeof(struct port));
			p->resource_id = xmlNodeListGetString(node->doc, node->children, 1);
			p->op = ADD;
			p->dpid = dpid;
			list_append_data(LSI(data)->res.port_list_add, p);

			nc_verb_verbose("added to list: dpid=%lx port %s with op=%u\n", p->dpid, p->resource_id, p->op);
		} else {
			// nodeNr > 1 ==> already attached port
			nc_verb_verbose("attachment failed dpid=%lx port %s: port already attached.\n", dpid, XML_GET_CONTENT(node->children));
			rv = EXIT_FAILURE;
		}

		xmlXPathFreeObject(xpath_obj_ptr);

	} else if (XMLDIFF_REM & op) {

		if (NULL == LSI(data)->res.port_list_del) {
			LSI(data)->res.port_list_del = list_new();
			assert(((struct lsi* ) *data)->res.port_list_del);
		}
		struct port *p = calloc(1, sizeof(struct port));
		p->resource_id = xmlNodeListGetString(node->doc, node->children, 1);
		p->op = DELETE;
		p->dpid = dpid;
		list_append_data(LSI(data)->res.port_list_del, p);

		nc_verb_verbose("added to list: dpid=%lx port %s with op=%u\n", p->dpid, p->resource_id, p->op);

	} else {
		// todo implement
		nc_verb_error("not implemented");
		assert(0);
	}

	return rv;
}
コード例 #23
0
ファイル: of-config1.1.1.c プロジェクト: bisdn/of-config
/* !DO NOT ALTER FUNCTION SIGNATURE! */
int callback_ofc_capable_switch_ofc_logical_switches_ofc_switch (void ** data, XMLDIFF_OP op, xmlNodePtr node, struct nc_err** error)
{
	nc_verb_verbose("%s: data=%p, op=%d\n", __PRETTY_FUNCTION__, data, op);
	print_element_names(node, 0);

	if (NULL == ofc_state.lsi_list) {
		ofc_state.lsi_list = list_new();
		assert(ofc_state.lsi_list);
	}

	assert(data);
	assert(*data);

	if (!(XMLDIFF_REM & op)) {
		list_append_data(ofc_state.lsi_list, *data);
	}

	int rv = EXIT_SUCCESS;
	if (XMLDIFF_ADD & op) {
		assert(XMLDIFF_CHAIN & op);

		nc_verb_verbose("create new lsi (dpid=%lu, name=%s)\n", LSI(data)->dpid, LSI(data)->dpname);
		if (lsi_create(ofc_state.xmp_client_handle, *data)) {
			rv = EXIT_FAILURE;
		}

	} else if (XMLDIFF_REM& op) {
		assert(XMLDIFF_CHAIN & op);

		nc_verb_verbose("destroy lsi (dpid=%lu, name=%s)\n", LSI(data)->dpid, LSI(data)->dpname);
		if ( lsi_destroy(ofc_state.xmp_client_handle, LSI(data)->dpid) ) {
			rv = EXIT_FAILURE;
		}

		// cannot have a port add during a lsi destroy
		assert(NULL == LSI(data)->res.port_list_add);

		// check if there were ports attached, then clean the list, because detachment takes place during lsi destruction
		if (NULL != LSI(data)->res.port_list_del) {
			struct port *p;
			while ((p = list_pop_head(LSI(data)->res.port_list_del))) {
				xmlFree(p->resource_id);
				free(p);
			}
		}

		// no need to deal with controllers seperately here

		lsi_cleanup(*data);


	} else if (XMLDIFF_MOD & op) {
		// direct sub elements changed
		nc_verb_error("not implemented XMLDIFF_MOD");
		assert(0);
	} else if (XMLDIFF_CHAIN & op) {
		// resources or controllers changed (attachment of ports handled in parent)

		nc_verb_verbose("XMLDIFF_CHAIN\n");

		// check dpid
		if (0 == LSI(data)->dpid) {
			xmlNodePtr tmp = find_element(BAD_CAST "datapath-id",  node->children);
			assert(tmp);
			uint64_t dpid = parse_dpid(tmp->children->content);

			if (LSI(data)->dpid != dpid) {
				LSI(data)->dpid = dpid;
			}
		}

		if (LSI(data)->controller_list_add) {
			lsi_connect_to_controller(ofc_state.xmp_client_handle, LSI(data));
		}

		if (LSI(data)->controller_list_del) {
			// fixme implement
			// assert(0);
		}

	} else {
		nc_verb_error("unsupported op");
		assert(0);
	}

	*data = NULL;

	return rv;
}
コード例 #24
0
ファイル: of-config1.1.1.c プロジェクト: bisdn/of-config
/* !DO NOT ALTER FUNCTION SIGNATURE! */
int callback_ofc_capable_switch_ofc_resources_ofc_port_ofc_features (void ** data, XMLDIFF_OP op, xmlNodePtr node, struct nc_err** error)
{
	nc_verb_verbose("%s: data=%p, op=%d\n", __PRETTY_FUNCTION__, data, op);
	print_element_names(node, 0);
	return EXIT_SUCCESS;
}