예제 #1
0
/* !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;
}
예제 #2
0
int
xml2_load (xmlNodePtr node, mr_ra_mr_ptrdes_t * ptrs)
{
  int idx = mr_add_ptr_to_list (ptrs);
  xmlNodePtr node_;
  char * content = NULL;
  char * property = NULL;

  if (idx < 0)
    return (idx);

  /* handle REF_IDX property */
  property = (char*)xmlGetProp (node, (unsigned char*)MR_REF_IDX);
  if (property)
    {
      if (1 != sscanf (property, "%" SCNd32, &ptrs->ra.data[idx].idx))
	MR_MESSAGE (MR_LL_WARN, MR_MESSAGE_READ_REF, property);
      ptrs->ra.data[idx].flags.is_referenced = MR_TRUE;
      xmlFree (property);
    }
  /* handle REF property */
  property = (char*)xmlGetProp (node, (unsigned char*)MR_REF);
  if (property)
    {
      if (1 != sscanf (property, "%" SCNd32, &ptrs->ra.data[idx].ref_idx))
	MR_MESSAGE (MR_LL_WARN, MR_MESSAGE_READ_REF, property);
      xmlFree (property);
    }
  /* handle REF_CONTENT property */
  property = (char*)xmlGetProp (node, (unsigned char*)MR_REF_CONTENT);
  if (property)
    {
      if (1 != sscanf (property, "%" SCNd32, &ptrs->ra.data[idx].ref_idx))
	MR_MESSAGE (MR_LL_WARN, MR_MESSAGE_READ_REF, property);
      else
	ptrs->ra.data[idx].flags.is_content_reference = MR_TRUE;
      xmlFree (property);
    }
  property = (char*)xmlGetProp (node, (unsigned char*)MR_ISNULL);
  if (property)
    {
      ptrs->ra.data[idx].flags.is_null= MR_TRUE;
      xmlFree (property);
    }

  for (node_ = node->xmlChildrenNode; node_ && !content; node_ = node_->next)
    content = (char*)XML_GET_CONTENT (node_);

  ptrs->ra.data[idx].mr_value.value_type = MR_VT_UNKNOWN;
  ptrs->ra.data[idx].mr_value.vt_string = content ? MR_STRDUP (content) : MR_STRDUP ("");
  ptrs->ra.data[idx].fd.name.str = MR_STRDUP ((char*)node->name);

  /* loop on subnodes */
  for (node_ = node->xmlChildrenNode; node_; node_ = node_->next)
    if (XML_ELEMENT_NODE == node_->type)
      mr_add_child (idx, xml2_load (node_, ptrs), ptrs);

  return (idx);
}
예제 #3
0
/* !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;
}
예제 #4
0
파일: response.c 프로젝트: Grantley/libsdb
/**
 * Parse the metadata section of a response
 * 
 * @param response the response data structure (must be initalized)
 * @param metadata the metadata node
 * @return SDB_OK if no errors occurred
 */
int sdb_response_parse_metadata(struct sdb_response* response, xmlNodePtr metadata)
{
	xmlNodePtr cur, content;
	for (cur = metadata->children; cur != NULL; cur = cur->next) {
		
		
		// The box usage statistic
		
		if (strcmp((char*) cur->name, "BoxUsage") == 0) {
			assert(cur->children != NULL);
			content = cur->children;
			assert(XML_GET_CONTENT(content) != NULL);
			
			char* e = NULL;
			char* str_content = (char*) XML_GET_CONTENT(content);
			response->box_usage = strtod(str_content, &e);
			if (response->box_usage < 0 || e == NULL || *e != '\0') {
				response->box_usage = 0;
				if (response->internal->errout != NULL) {
					fprintf(response->internal->errout, "SimpleDB ERROR: Invalid box usage \"%s\" in the AWS meta-data response\n", XML_GET_CONTENT(content));
				}
				return SDB_E_INVALID_META_RESPONSE;
			}
			continue;
		}
		
		
		// The list of nodes to ignore
		
		if (strcmp((char*) cur->name, "RequestID") == 0) continue;
		if (strcmp((char*) cur->name, "RequestId") == 0) continue;
		
		
		// Handle errors
		
		if (response->internal->errout != NULL) {
			fprintf(response->internal->errout, "SimpleDB ERROR: Invalid node \"%s\" in the AWS meta-data response\n", cur->name);
		}
		return SDB_E_INVALID_META_RESPONSE;
	}
	
	return SDB_OK;
}
예제 #5
0
/* !DO NOT ALTER FUNCTION SIGNATURE! */
int callback_ofc_capable_switch_ofc_logical_switches_ofc_switch_ofc_controllers_ofc_controller_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);

	assert(__data);

	if ((XMLDIFF_ADD) & op) {

		CONTROLLER(__data)->port = strtoul(XML_GET_CONTENT(node->children), NULL, 10);

	} else if ((XMLDIFF_REM) & op) {
	} else {
		nc_verb_error("not implemented");
		assert(0);
	}

	return EXIT_SUCCESS;
}
예제 #6
0
/* !DO NOT ALTER FUNCTION SIGNATURE! */
int callback_ofc_capable_switch_ofc_logical_switches_ofc_switch_ofc_controllers_ofc_controller_ofc_ip_address (void ** data, XMLDIFF_OP op, xmlNodePtr node, struct nc_err** error)
{
	nc_verb_verbose("%s: data=%p, op=%d\n", __PRETTY_FUNCTION__, data, op);
	assert(__data);

	if ((XMLDIFF_ADD) & op) {

		// fixme handle zone in address (see http://www.netconfcentral.org/modules/ietf-inet-types)
		CONTROLLER(__data)->ip_domain = parse_ip_address(XML_GET_CONTENT(node->children), &CONTROLLER(__data)->ip);

	} else if ((XMLDIFF_REM) & op) {
	} else {
		nc_verb_error("not implemented");
		assert(0);
	}

	return EXIT_SUCCESS;
}
예제 #7
0
/* !DO NOT ALTER FUNCTION SIGNATURE! */
int callback_ofc_capable_switch_ofc_logical_switches_ofc_switch_ofc_controllers_ofc_controller_ofc_id (void ** data, XMLDIFF_OP op, xmlNodePtr node, struct nc_err** error)
{
	nc_verb_verbose("%s: data=%p, op=%d\n", __PRETTY_FUNCTION__, data, op);

	assert(NULL == __data);

	if ((XMLDIFF_ADD|XMLDIFF_REM) & op) {
		__data = calloc(1, sizeof(struct controller));

		CONTROLLER(__data)->id = strdup(XML_GET_CONTENT(node->children));
		assert(CONTROLLER(__data)->id);

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

	return EXIT_SUCCESS;
}
예제 #8
0
void parse_cache(char *filename)
{
	xmlDoc *doc = NULL;
	xmlNode *root_element = NULL;
	xmlNode *neighbor = NULL;
	char *c;

	LIBXML_TEST_VERSION;

	/*parse the file and get the DOM */
	doc = xmlReadFile(cache_path, NULL, 0);	

	/*Get the root element node */
	root_element = xmlDocGetRootElement(doc);
	neighbor = root_element->children;

	while(neighbor != NULL)
	{
		if( !STRCMP(neighbor->name,"neighbor") )
		{
			struct in6_addr lla;
			struct ether_addr mac, eth;
			xmlNode *param = neighbor->children;
			uint16_t vlan_id = 4095;

			while(param != NULL)
			{
				if (param->type == XML_ELEMENT_NODE)
				{
					if( !STRCMP(param->name,"mac") )
					{
						c=(char *)XML_GET_CONTENT(param->children);
						memcpy(&mac,ether_aton(c),sizeof(struct ether_addr));
/*						memcpy(&mac,ether_aton((char *)XML_GET_CONTENT(param->children)),sizeof(struct ether_addr));	*/
						add_neighbor(&neighbors, vlan_id, mac);
					}
					else if( !STRCMP(param->name,"vlan_id") ) {
						char *text = (char*)XML_GET_CONTENT(param->children);
						vlan_id = atoi(text!=NULL?text:"4095");
					}
					else if( !STRCMP(param->name,"time") )
					{
						c=(char *)XML_GET_CONTENT(param->children);
						set_neighbor_timer(&neighbors, vlan_id, mac,atoi(c));
/*						set_neighbor_timer(&neighbors, mac,atoi((char *)XML_GET_CONTENT(param->children)));		*/
					}
					else if( !STRCMP(param->name,"lla") )
					{
						if(param->children != NULL)
						{
							inet_pton(AF_INET6,(char *)XML_GET_CONTENT(param->children), &lla);
							set_neighbor_lla(&neighbors, vlan_id, mac, lla);
						}
					}
					else if( !STRCMP(param->name,"addresses") )
					{
						xmlNode *address = param->children;
						while(address != NULL)
						{
							if (address->type == XML_ELEMENT_NODE)
							{
								if( !STRCMP(address->name,"address") )
								{
									struct in6_addr addr;
									struct _xmlAttr *attr = address->properties;
									inet_pton(AF_INET6,(char *)XML_GET_CONTENT(address->children), &addr);
									add_neighbor_ip(&neighbors, vlan_id, mac, addr);

									while(attr != NULL)
									{
										if (attr->type == XML_ATTRIBUTE_NODE)
										{
											if( !STRCMP(attr->name,"lastseen") )
											{
												set_neighbor_address_timer(&neighbors, vlan_id, mac, addr, (time_t) atoi((const char *)(attr->children->content)));
											}
											else if ( !STRCMP(attr->name,"firstseen") )
											{
												set_neighbor_first_address_timer(&neighbors, vlan_id, mac, addr, (time_t) atoi((const char *)(attr->children->content)));
											}
										}
										attr = attr->next;
									}

								}
							}
							address = address->next;
						}
					}
					else if( !STRCMP(param->name,"old_mac") )
					{
						xmlNode *old = param->children;
						while(old != NULL)
						{
							if (old->type == XML_ELEMENT_NODE)
							{
								if( !STRCMP(old->name,"mac") )
								{
									struct _xmlAttr *attr = old->properties;
									
									memcpy(&eth,ether_aton((char *)XML_GET_CONTENT(old->children)),sizeof(struct ether_addr));
									add_neighbor_old_mac(&neighbors, vlan_id, lla, eth);
									
									while(attr != NULL)
									{
										if (attr->type == XML_ATTRIBUTE_NODE)
										{
											if( !STRCMP(attr->name,"last") )
											{
												neighbor_set_last_mac(&neighbors, vlan_id, lla, eth);
											}
										}
										attr = attr->next;
									}

								}
							}
							old = old->next;
						}
					}
								
				}
				param = param->next;
			}
		}
		neighbor = neighbor->next;
	}

	xmlFreeDoc(doc);
	return;
}
예제 #9
0
void parse_routers()
{
        xmlDoc *doc = NULL;
        xmlNode *root_element = NULL;
        xmlNode *current = NULL;
        char* c;

	/*parse the file and get the DOM */
        doc = xmlReadFile(config_path, NULL, 0);	

	/*Get the root element node */
        root_element = xmlDocGetRootElement(doc);
        current = root_element->children;

	request ="/config_ndpmon/actions_low_pri/sendmail/text()";
	xmlobject = xmlXPathEval ((xmlChar*)request, xpctxt);
	if ((xmlobject->nodesetval!=NULL) || (strcmp("1", (char*)xmlobject->nodesetval->nodeTab[0]->content)!=0)) action_low_pri.sendmail=0;
	else action_low_pri.sendmail=1; 
	xmlXPathFreeObject (xmlobject);


	while(current != NULL)
	{
		if (current->type == XML_ELEMENT_NODE)
		{
			if( !STRCMP(current->name,"routers") )
			{
				xmlNode *router = current->children;
				while(router != NULL)
				{
					if (router->type == XML_ELEMENT_NODE)
					{
						if( !STRCMP(router->name,"router") )
						{
							struct ether_addr mac;
							struct in6_addr lla;
							uint8_t  param_curhoplimit=0;
							uint8_t  param_flags_reserved=0;
							uint16_t param_router_lifetime=0;
							uint32_t param_reachable_timer=0;
							uint32_t param_retrans_timer=0;
							xmlNode *param = router->children;
							while(param != NULL)
							{
								if (param->type == XML_ELEMENT_NODE)
								{
									if( !STRCMP(param->name,"mac") )
									{
										memcpy(&mac,ether_aton((char *)XML_GET_CONTENT(param->children)),sizeof(struct ether_addr));
									}
									else if( !STRCMP(param->name,"lla") )
									{
										inet_pton(AF_INET6,(char *)XML_GET_CONTENT(param->children), &lla);
									}
									else if( !STRCMP(param->name,"param_curhoplimit") )
									{
										char* text = (char*)XML_GET_CONTENT(param->children);
										param_curhoplimit = atoi(text!=NULL?text:"0");
									}
									else if( !STRCMP(param->name,"param_flags_reserved") )
									{
										char* text = (char*)XML_GET_CONTENT(param->children);
										param_flags_reserved = atoi(text!=NULL?text:"0");
									}
									else if( !STRCMP(param->name,"param_router_lifetime") )
									{
										char* text = (char*)XML_GET_CONTENT(param->children);
										param_router_lifetime = atoi(text!=NULL?text:"0");
									}
									else if( !STRCMP(param->name,"param_reachable_timer") )
									{
										char* text = (char*)XML_GET_CONTENT(param->children);
										param_reachable_timer = atoi(text!=NULL?text:"0");
									}
									else if( !STRCMP(param->name,"param_retrans_timer") )
									{
										char* text = (char*)XML_GET_CONTENT(param->children);
										param_retrans_timer = atoi(text!=NULL?text:"0");
										add_router(&routers, &mac, &lla, param_curhoplimit, param_flags_reserved, param_router_lifetime, param_reachable_timer, param_retrans_timer);
									}
									else if( !STRCMP(param->name,"addresses") )
									{
										xmlNode *address = param->children;
										while(address != NULL)
										{
											if (address->type == XML_ELEMENT_NODE)
											{
												if( !STRCMP(address->name,"address") )
												{
													struct in6_addr addr;
													inet_pton(AF_INET6,(char *)XML_GET_CONTENT(address->children), &addr);
													add_router_address(&routers, mac, addr);
												}
											}
											address = address->next;
										}
									}
									else if( !STRCMP(param->name,"prefixes") )
									{
										xmlNode *prefix = param->children;
										while(prefix != NULL)
										{
											if (prefix->type == XML_ELEMENT_NODE)
											{
												if( !STRCMP(prefix->name,"prefix") )
												{
													struct in6_addr addr;
													int mask=0;
													char buffer[INET6_ADDRSTRLEN];
													struct _xmlAttr *attr = prefix->properties;

													while(attr != NULL)
													{
														if (attr->type == XML_ATTRIBUTE_NODE)
														{
															if( !STRCMP(attr->name,"mask") )
															{
																c=(char *)XML_GET_CONTENT(attr->children);
																mask = atoi(c);
/*																mask = atoi((char *)XML_GET_CONTENT(attr->children));  */
															}
														}
														attr = attr->next;
													}

													c=(char *)XML_GET_CONTENT(prefix->children);
													strncpy(buffer,c, INET6_ADDRSTRLEN);
/*													strcpy(buffer,(char *)XML_GET_CONTENT(prefix->children));	*/
													inet_pton(AF_INET6,buffer, &addr);

													add_prefix(&routers, lla, mac, addr,mask);
												}
											}
											prefix = prefix->next;
										}
									}
								}
								param = param->next;
							}
						}
					}
					router = router->next;
				}
			}
		}
		current = current->next;
	}

	xmlFreeDoc(doc);
	return;
}
예제 #10
0
/*
 * Routers
 * */
void parse_routers()
{
	xmlXPathObjectPtr xmlobject;
	xmlNode *router;
        char *text, *request="/config_ndpmon/routers";

	xmlobject = xmlXPathEval ((xmlChar*)request, xpctxt);
	if (xmlobject->nodesetval==NULL) {
		xmlXPathFreeObject (xmlobject);
		return;
        }
	router = xmlobject->nodesetval->nodeTab[0]->children;

	while(router != NULL) {
		if (router->type == XML_ELEMENT_NODE && STRCMP(router->name,"router")==0) {
			struct ether_addr mac;
			struct in6_addr lla;
			uint8_t  param_curhoplimit=0;
			uint8_t  param_flags_reserved=0;
			uint16_t param_router_lifetime=0;
			uint32_t param_reachable_timer=0;
			uint32_t param_retrans_timer=0;
			uint32_t param_mtu=0;
			int params_volatile=1;
			prefix_t* tmp_prefix = NULL;
			address_t* tmp_address = NULL;
			xmlNode *param = router->children;
			int vlan_id = 4095;
			while(param != NULL) {
				if (param->type != XML_ELEMENT_NODE) {
					param = param->next;
					continue;
				}
                                /* We have an XML Element: */
				if( !STRCMP(param->name,"mac") ) {
					memcpy(&mac,ether_aton((char *)XML_GET_CONTENT(param->children)),sizeof(struct ether_addr));
				}
				else if( !STRCMP(param->name,"vlan_id") ) {
					text = (char*)XML_GET_CONTENT(param->children);
					vlan_id = atoi(text!=NULL?text:"4095");
				}
				else if( !STRCMP(param->name,"lla") ) {
					inet_pton(AF_INET6,(char *)XML_GET_CONTENT(param->children), &lla);
				}
				else if( !STRCMP(param->name,"param_curhoplimit") ) {
					text = (char*)XML_GET_CONTENT(param->children);
					param_curhoplimit = atoi(text!=NULL?text:"0");
					}
				else if( !STRCMP(param->name,"param_flags_reserved") ) {
					text = (char*)XML_GET_CONTENT(param->children);
					param_flags_reserved = atoi(text!=NULL?text:"0");
					}
				else if( !STRCMP(param->name,"param_router_lifetime") ) {
					text = (char*)XML_GET_CONTENT(param->children);
					param_router_lifetime = atoi(text!=NULL?text:"0");
				}
				else if( !STRCMP(param->name,"param_reachable_timer") ) {
					text = (char*)XML_GET_CONTENT(param->children);
					param_reachable_timer = strtoul(text!=NULL?text:"0", NULL, 10);
				}
				else if( !STRCMP(param->name,"param_retrans_timer") ) {
					text = (char*)XML_GET_CONTENT(param->children);
					param_retrans_timer = strtoul(text!=NULL?text:"0", NULL, 10);
				}
				else if( !STRCMP(param->name,"param_mtu") ) {
					text = (char*)XML_GET_CONTENT(param->children);
					param_mtu = strtoul(text!=NULL?text:"0", NULL, 10);
				}
				else if( !STRCMP(param->name,"params_volatile") ) {
					text = (char*)XML_GET_CONTENT(param->children);
					params_volatile = atoi(text!=NULL?text:"1");
				}
				else if( !STRCMP(param->name,"addresses") ) {
					xmlNode *address = param->children;
					while(address != NULL) {
						if (address->type == XML_ELEMENT_NODE &&  STRCMP(address->name,"address")==0 ) {
							/* Read address: */
							address_t* new_address = malloc(sizeof(address_t));
							if (new_address==NULL) {
								fprintf(stderr, "malloc failed.");
							}
							inet_pton(AF_INET6,(char *)XML_GET_CONTENT(address->children), &new_address->address);
							/* Add address to tmp address list: */
							new_address->next = tmp_address;
							tmp_address = new_address;
						}
						/* Fetch next address node: */
						address = address->next;
					}
				} /* end addresses */
				else if( !STRCMP(param->name,"prefixes") ) {
					xmlNode *prefix = param->children;
					while(prefix != NULL) {
						if (prefix->type == XML_ELEMENT_NODE && STRCMP(prefix->name,"prefix")==0) {
							/* Read prefix params: */
							xmlNode *prefix_param = prefix->children;
							prefix_t* new_prefix = malloc(sizeof(prefix_t));
							char buffer[INET6_ADDRSTRLEN];
							if (new_prefix==NULL) {
								fprintf(stderr, "malloc failed.");
							}
							memset(&new_prefix->prefix, 0, sizeof(struct in6_addr));
							new_prefix->mask = 0;
							new_prefix->param_valid_time = 0;
							new_prefix->param_preferred_time = 0;
							while(prefix_param != NULL) {
								if (prefix_param->type != XML_ELEMENT_NODE) {
									prefix_param = prefix_param->next;
									continue;
								}
				                                /* We have an XML Element: */
								if (STRCMP(prefix_param->name,"address")==0) {
									text=(char *)XML_GET_CONTENT(prefix_param->children);
									strncpy(buffer,text, INET6_ADDRSTRLEN);
									inet_pton(AF_INET6,buffer, &new_prefix->prefix);
								}
								else if (STRCMP(prefix_param->name,"mask")==0) {
									text=(char *)XML_GET_CONTENT(prefix_param->children);
									new_prefix->mask = atoi(text!=NULL?text:0);
								}
								else if (STRCMP(prefix_param->name,"param_flags_reserved")==0) {
									text=(char *)XML_GET_CONTENT(prefix_param->children);
									new_prefix->param_flags_reserved = atoi(text!=NULL?text:0);
								}
								else if (STRCMP(prefix_param->name,"param_valid_time")==0) {
									text=(char *)XML_GET_CONTENT(prefix_param->children);
									new_prefix->param_valid_time = strtoul(text!=NULL?text:"0", NULL, 10);
								}
								else if (STRCMP(prefix_param->name,"param_preferred_time")==0) {
									text=(char *)XML_GET_CONTENT(prefix_param->children);
									new_prefix->param_preferred_time = strtoul(text!=NULL?text:"0", NULL, 10);
								}
								prefix_param = prefix_param->next;
							}
							/* Add prefix to tmp list:*/
							new_prefix->next = tmp_prefix;
							tmp_prefix = new_prefix;
						}
						/* Fetch next prefix node: */
						prefix = prefix->next;
					}
				} /* end prefixes */
				/* Fetch next router param: */
				param = param->next;
			} /* end router params */
			/* Add router to the router list: */
			router_add(
				&routers, vlan_id, &mac, &lla,
				param_curhoplimit,
				param_flags_reserved,
				param_router_lifetime,
				param_reachable_timer,
				param_retrans_timer,
				param_mtu,
				params_volatile
			);
			while (tmp_prefix!=NULL) {
				prefix_t* current=tmp_prefix;
				router_add_prefix(
					routers, vlan_id, lla, mac,
					current->prefix,
					current->mask,
					current->param_flags_reserved,
					current->param_valid_time,
					current->param_preferred_time
				);
				tmp_prefix = current->next;
				free(current);
			}
			while (tmp_address!=NULL) {
				address_t* current=tmp_address;
				router_add_address(routers, vlan_id, mac, current->address);
				tmp_address = current->next;
				free(current);
			}
		} /* end is XML element and router */
		/* Fetch next router node: */
		router = router->next;
	}
	xmlXPathFreeObject (xmlobject);
}
예제 #11
0
/* !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;
}
예제 #12
0
파일: response.c 프로젝트: Grantley/libsdb
/**
 * Parse the list of items
 * 
 * @param response the response data structure (must be initalized)
 * @param items the list of items
 * @return SDB_OK if no errors occurred
 */
int sdb_response_parse_items(struct sdb_response* response, xmlNodePtr items)
{
	xmlNodePtr cur, content;
	int size = 0;
	
	
	// Count the attributes and determine whether we have more incoming data
	 
	response->has_more = FALSE;
	
	for (cur = items->children; cur != NULL; cur = cur->next) {
		
		
		// The item
		
		if (strcmp((char*) cur->name, "Item") == 0 || strcmp((char*) cur->name, "ItemName") == 0) {
			size++;
			continue;
		}
		
		
		// The next token
		
		if (strcmp((char*) cur->name, "NextToken") == 0) {
			assert(cur->children != NULL);
			content = cur->children;
			response->internal->next_token = XML_GET_CONTENT(content); 
			assert(response->internal->next_token != NULL);
			response->has_more = TRUE;
			continue;
		}
		
		
		// The list of nodes to ignore
		
		if (strcmp((char*) cur->name, "RequestID") == 0) continue;
		if (strcmp((char*) cur->name, "RequestId") == 0) continue;
		
		
		// Handle errors
		
		if (response->internal->errout != NULL) {
			fprintf(response->internal->errout, "SimpleDB ERROR: Invalid node \"%s\" in the AWS list of items\n", cur->name);
		}
		return SDB_E_INVALID_META_RESPONSE;
	}
	
	
	// Allocate the memory if this is a new result set, otherwise prepare to append
	
	int start = 0;
	
	if (response->type == SDB_R_NONE) {
		
		response->size = size;
		response->type = SDB_R_ITEM_LIST;
		response->items = (struct sdb_item*) malloc(size * sizeof(struct sdb_item));  
	}
	else if (response->type == SDB_R_ITEM_LIST) {
		
		struct sdb_item* old = response->items;
		int newsize = response->size + size;
		start = response->size;
		
		response->items = (struct sdb_item*) malloc(newsize * sizeof(struct sdb_item));
		memcpy(response->items, old, response->size * sizeof(struct sdb_item));
		free(old);
		
		response->size = newsize;
	}
	else assert(0);
	
	
	
	// Pull out the items 
	
	int index = start;
	for (cur = items->children; cur != NULL; cur = cur->next) {
		
		
		// Item name
		
		if (strcmp((char*) cur->name, "ItemName") == 0) {
			assert(cur->children != NULL);
			content = cur->children;
			response->items[index].name = (char*) XML_GET_CONTENT(content);
			response->items[index].size = 0; 
			response->items[index].attributes = NULL; 
			assert(response->items[index].name != NULL);
			index++;
			continue;
		}
		
		
		// Item with attributes
		
		if (strcmp((char*) cur->name, "Item") == 0) {
			SDB_SAFE(sdb_response_parse_item(response, &response->items[index++], cur));
		}
	}
	
	assert(index - start == size);
	
	return SDB_OK;
}
예제 #13
0
파일: response.c 프로젝트: Grantley/libsdb
/**
 * Parse a single item
 * 
 * @param response the response data structure
 * @param item the item data structure
 * @param node the item node
 * @return SDB_OK if no errors occurred
 */
int sdb_response_parse_item(struct sdb_response* response, struct sdb_item* item, xmlNodePtr node)
{
	xmlNodePtr cur, cur2, content;
	int size = 0;
	
	
	// Count the attributes and determine whether we have more incoming data
	
	for (cur = node->children; cur != NULL; cur = cur->next) {
		
		
		// The attribute
		
		if (strcmp((char*) cur->name, "Attribute") == 0) {
			size++;
			continue;
		}
		
		
		// The item name
		
		if (strcmp((char*) cur->name, "Name") == 0) continue;
		
		
		// Handle errors
		
		return SDB_E_INVALID_META_RESPONSE;
	}
	
	
	// Allocate the memory if this is a new result set, otherwise prepare to append
	
	item->size = size;
	item->attributes = (struct sdb_attribute*) malloc(size * sizeof(struct sdb_attribute));  
	
	
	// Pull out the attributes and the item name 
	
	int index = 0;
	item->name = NULL;
	
	for (cur = node->children; cur != NULL; cur = cur->next) {
		
		
		// The item name
		
		if (strcmp((char*) cur->name, "Name") == 0) { 
			assert(cur->children != NULL);
			content = cur->children;
			assert(XML_GET_CONTENT(content) != NULL);
			item->name = (char*) XML_GET_CONTENT(content);
			continue;
		} 
		
		
		// The attribute
		
		if (strcmp((char*) cur->name, "Attribute") == 0) {
			struct sdb_attribute* a = &(item->attributes[index++]);
			a->name = a->value = NULL;
			
			for (cur2 = cur->children; cur2 != NULL; cur2 = cur2->next) {
				
				if (strcmp((char*) cur2->name, "Name") == 0) { 
					assert(cur2->children != NULL);
					content = cur2->children;
					assert(XML_GET_CONTENT(content) != NULL);
					a->name = (char*) XML_GET_CONTENT(content);
					continue;
				} 
				
				if (strcmp((char*) cur2->name, "Value") == 0) { 
					if (cur2->children == NULL) {
						a->value = response->internal->empty_string;
						continue;
					}
					else {
						content = cur2->children;
						assert(XML_GET_CONTENT(content) != NULL);
						a->value = (char*) XML_GET_CONTENT(content);
						continue;
					}
				} 
				
				
				// Handle errors
		
				return SDB_E_INVALID_META_RESPONSE;
			}
			
			
			// Check for incomplete attributes
			
			if (a->name == NULL || a->value == NULL) {
				return SDB_E_INVALID_META_RESPONSE;
			}
		}
	}
	
	assert(item->name);
	assert(index == size);
	
	return SDB_OK;
}
예제 #14
0
파일: response.c 프로젝트: Grantley/libsdb
/**
 * Parse the list of attributes
 * 
 * @param response the response data structure (must be initalized)
 * @param attributes the list of attributes
 * @return SDB_OK if no errors occurred
 */
int sdb_response_parse_attributes(struct sdb_response* response, xmlNodePtr attributes)
{
	xmlNodePtr cur, cur2, content;
	int size = 0;
	
	
	// Count the attributes and determine whether we have more incoming data
	 
	response->has_more = FALSE;
	
	for (cur = attributes->children; cur != NULL; cur = cur->next) {
		
		
		// The attribute
		
		if (strcmp((char*) cur->name, "Attribute") == 0) {
			size++;
			continue;
		}
		
		
		// The next token
		
		if (strcmp((char*) cur->name, "NextToken") == 0) {
			assert(cur->children != NULL);
			content = cur->children;
			response->internal->next_token = XML_GET_CONTENT(content); 
			assert(response->internal->next_token != NULL);
			response->has_more = TRUE;
			continue;
		}
		
		
		// The list of nodes to ignore
		
		if (strcmp((char*) cur->name, "RequestID") == 0) continue;
		if (strcmp((char*) cur->name, "RequestId") == 0) continue;
		
		
		// Handle errors
		
		if (response->internal->errout != NULL) {
			fprintf(response->internal->errout, "SimpleDB ERROR: Invalid node \"%s\" in the AWS list of attributes\n", cur->name);
		}
		return SDB_E_INVALID_META_RESPONSE;
	}
	
	
	// Allocate the memory if this is a new result set, otherwise prepare to append
	
	int start = 0;
	
	if (response->type == SDB_R_NONE) {
		
		response->size = size;
		response->type = SDB_R_ATTRIBUTE_LIST;
		response->attributes = (struct sdb_attribute*) malloc(size * sizeof(struct sdb_attribute));  
	}
	else if (response->type == SDB_R_ATTRIBUTE_LIST) {
		
		struct sdb_attribute* old = response->attributes;
		int newsize = response->size + size;
		start = response->size;
		
		response->attributes = (struct sdb_attribute*) malloc(newsize * sizeof(struct sdb_attribute));
		memcpy(response->attributes, old, response->size * sizeof(struct sdb_attribute));
		free(old);
		
		response->size = newsize;
	}
	else assert(0);
	
	
	
	// Pull out the attributes 
	
	int index = start;
	for (cur = attributes->children; cur != NULL; cur = cur->next) {
		
		
		// The attribute name
		
		if (strcmp((char*) cur->name, "Attribute") == 0) {
			struct sdb_attribute* a = &(response->attributes[index++]);
			a->name = a->value = NULL;
			
			for (cur2 = cur->children; cur2 != NULL; cur2 = cur2->next) {
				
				if (strcmp((char*) cur2->name, "Name") == 0) { 
					assert(cur2->children != NULL);
					content = cur2->children;
					assert(XML_GET_CONTENT(content) != NULL);
					a->name = (char*) XML_GET_CONTENT(content);
					continue;
				} 
				
				if (strcmp((char*) cur2->name, "Value") == 0) { 
					if (cur2->children == NULL) {
						a->value = response->internal->empty_string;
						continue;
					}
					else {
						content = cur2->children;
						assert(XML_GET_CONTENT(content) != NULL);
						a->value = (char*) XML_GET_CONTENT(content);
						continue;
					}
				} 
				
				
				// Handle errors
		
				if (response->internal->errout != NULL) {
					fprintf(response->internal->errout, "SimpleDB ERROR: Invalid node \"%s\" in the AWS attribute\n", cur2->name);
				}
				return SDB_E_INVALID_META_RESPONSE;
			}
			
			
			// Check for incomplete attributes
			
			if (a->name == NULL || a->value == NULL) {
				if (response->internal->errout != NULL) {
					fprintf(response->internal->errout, "SimpleDB ERROR: Incomplete attribute in the AWS response\n");
				}
				return SDB_E_INVALID_META_RESPONSE;
			}
		}
	}
	
	assert(index - start == size);
	
	return SDB_OK;
}
예제 #15
0
파일: response.c 프로젝트: Grantley/libsdb
/**
 * Parse the list of domains
 * 
 * @param response the response data structure (must be initalized)
 * @param domains the list of domains
 * @return SDB_OK if no errors occurred
 */
int sdb_response_parse_domains(struct sdb_response* response, xmlNodePtr domains)
{
	xmlNodePtr cur, content;
	int size = 0;
	
	
	// Count the domains and determine whether we have more incoming data
	 
	response->has_more = FALSE;
	
	for (cur = domains->children; cur != NULL; cur = cur->next) {
		
		
		// The domain name
		
		if (strcmp((char*) cur->name, "DomainName") == 0) {
			size++;
			continue;
		}
		
		
		// The next token
		
		if (strcmp((char*) cur->name, "NextToken") == 0) {
			assert(cur->children != NULL);
			content = cur->children;
			response->internal->next_token = XML_GET_CONTENT(content); 
			assert(response->internal->next_token != NULL);
			response->has_more = TRUE;
			continue;
		}
		
		
		// The list of nodes to ignore
		
		if (strcmp((char*) cur->name, "RequestID") == 0) continue;
		if (strcmp((char*) cur->name, "RequestId") == 0) continue;
		
		
		// Handle errors
		
		if (response->internal->errout != NULL) {
			fprintf(response->internal->errout, "SimpleDB ERROR: Invalid node \"%s\" in the AWS list of domains\n", cur->name);
		}
		return SDB_E_INVALID_META_RESPONSE;
	}
	
	
	// Allocate the memory if this is a new result set, otherwise prepare to append
	
	int start = 0;
	
	if (response->type == SDB_R_NONE) {
		
		response->size = size;
		response->type = SDB_R_DOMAIN_LIST;
		response->domains = (char**) malloc(size * sizeof(char*));  
	}
	else if (response->type == SDB_R_DOMAIN_LIST) {
		
		char** old = response->domains;
		int newsize = response->size + size;
		start = response->size;
		
		response->domains = (char**) malloc(newsize * sizeof(char*));
		memcpy(response->domains, old, response->size * sizeof(char*));
		free(old);
		
		response->size = newsize;
	}
	else assert(0);
	
	
	
	// Pull out the domain names 
	
	int index = start;
	for (cur = domains->children; cur != NULL; cur = cur->next) {
		
		
		// The domain name
		
		if (strcmp((char*) cur->name, "DomainName") == 0) {
			assert(cur->children != NULL);
			content = cur->children;
			assert(XML_GET_CONTENT(content) != NULL);
			response->domains[index++] = (char*) XML_GET_CONTENT(content); 
		}
	}
	
	assert(index - start == size);
	
	return SDB_OK;
}
예제 #16
0
파일: response.c 프로젝트: Grantley/libsdb
/**
 * Parse the errors section of a response
 * 
 * @param response the response data structure (must be initalized)
 * @param errors the errors node
 * @return SDB_OK if no errors occurred
 */
int sdb_response_parse_errors(struct sdb_response* response, xmlNodePtr errors)
{
	xmlNodePtr topcur, cur, content; int i;
	char* str_content;

	int error_code = SDB_OK;
	char* message = NULL;

  	for (topcur = errors->children; topcur != NULL; topcur = topcur->next) {
		
		
		// Handle an error node
		
		if (strcmp((char*) topcur->name, "Error") == 0) {
			response->num_errors++;
			
			for (cur = topcur->children; cur != NULL; cur = cur->next) {
				
				// Parse the error code
				
				if (strcmp((char*) cur->name, "Code") == 0) {
					assert(cur->children != NULL);
					content = cur->children;
					assert(XML_GET_CONTENT(content) != NULL);
					
					if (response->error == 0) {
						str_content = (char*) XML_GET_CONTENT(content);
						for (i = 0; i < SDB_AWS_NUM_ERRORS; i++) {
							if (strcmp(SDB_AWS_ERRORS[i], str_content) == 0) {
								response->error = i;
							}
						}
						
						if (response->error == 0) {
							response->error = SDB_AWS_NUM_ERRORS;
							if (response->internal->errout != NULL) {
								fprintf(response->internal->errout, "SimpleDB ERROR: Unknown error code \"%s\"\n", str_content);
							}
						}
						
						error_code = response->error;
					}
					
					continue;
				}
				
				
				// Parse the error message
				
				if (strcmp((char*) cur->name, "Message") == 0) {
					assert(cur->children != NULL);
					content = cur->children;
					assert(XML_GET_CONTENT(content) != NULL);
					
					if (response->error_message == NULL) {
						response->error_message = (char*) XML_GET_CONTENT(content);
						message = (char*) XML_GET_CONTENT(content);
					} else if (response->internal->errout != NULL) {
						fprintf(response->internal->errout, "SimpleDB ERROR: %s\n", XML_GET_CONTENT(content));
					}
					continue;
				}
				
				
				// The list of nodes to ignore
				
				if (strcmp((char*) cur->name, "BoxUsage") == 0) continue;
				
				
				// Invalid Amazon response
				
				if (response->internal->errout != NULL) {
					fprintf(response->internal->errout, "SimpleDB ERROR: Invalid node \"%s\" in the AWS error response\n", cur->name);
				}
				return SDB_E_INVALID_ERR_RESPONSE;
			}
			
			continue;
		}
		
		
		// The list of nodes to ignore
		
		if (strcmp((char*) topcur->name, "BoxUsage") == 0) continue;
		
				
		// Handle errors
		
		if (response->internal->errout != NULL) {
			if (message != NULL) fprintf(response->internal->errout, "SimpleDB ERROR: %s\n", message);
			fprintf(response->internal->errout, "SimpleDB ERROR: Invalid node \"%s\" in the AWS error response\n", topcur->name);
		}
		return SDB_E_INVALID_ERR_RESPONSE;
	}
	
	
	// Print the error message if configured to do so

	if (response->internal->errout != NULL && message != NULL
	 && error_code != SDB_OK && error_code != SDB_E_AWS_SERVICE_UNAVAILABLE) {
		fprintf(response->internal->errout, "SimpleDB ERROR: %s\n", message);
	}
	
	return SDB_OK;
}