Ejemplo n.º 1
0
int open_session(SaHpiDomainIdT domainId, int eflag)
{
	Domain_t	*par_domain;

        if (!g_thread_supported()) {
                g_thread_init(NULL);
	};
	thread_wait = g_cond_new();
	thread_mutex = g_mutex_new();
	par_domain = (Domain_t *)malloc(sizeof(Domain_t));
	memset(par_domain, 0, sizeof(Domain_t));
	par_domain->domainId = domainId;
	if (get_sessionId(par_domain) != SA_OK) return(-1);
	// set current domain
	Domain = par_domain;

	if (eflag) {
		show_event_short = 1;
		prt_flag = 1;
		pthread_create(&ge_thread, NULL, get_event, NULL);
	};
	// add main domain to the domain list
	if (add_domain(par_domain) != SA_OK) return(-1);


	printf("\tEnter a command or \"help\" for list of commands\n");

	if (! eflag)
		pthread_create(&ge_thread, NULL, get_event, NULL);
	return 0;
}
Ejemplo n.º 2
0
void load_domain(char *line,kdomain *domain,int type){

    kdomain *temp_domain = domain, *new_domain,*s_domain;
    
    int i = 1;
    int splitcount;
    char **split_structure = malloc(sizeof(char *) * 4);;
    split_domain(line,split_structure);
    for(splitcount = 0; splitcount < 4;splitcount++){
        if(split_structure[splitcount] != NULL){
            if(split_structure[splitcount+1] == NULL){
                new_domain = new_domain_structure(split_structure[splitcount],type);
            }
            else
                new_domain = new_domain_structure(split_structure[splitcount],-1);

            if(split_structure[splitcount+1] == NULL)
                i = 0;
            
            temp_domain = add_domain(new_domain,temp_domain,i);
            free(split_structure[splitcount]);
        }

    }
    
    free(split_structure);

}
Ejemplo n.º 3
0
/**
 * returns the routing tree for the given domain, if domain's tree
 * doesnt exist, it will be created. If the trees are completely
 * filled and a not existing domain shall be added, an error is
 * returned
 *
 * @param domain the domain name of desired routing tree
 * @param rd route data to be searched
 *
 * @return a pointer to the root node of the desired routing tree,
 * NULL on failure
 */
struct route_tree_item * get_route_tree(const char * domain, struct carrier_tree * rd) {
	int i, id;
	struct route_tree * rt = NULL;
	if (!rd) {
		LM_ERR("NULL-pointer in parameter\n");
		return NULL;
	}
	for (i=0; i<rd->tree_num; i++) {
		if (rd->trees[i] && rd->trees[i]->name.s) {
			if (strcmp(rd->trees[i]->name.s, domain) == 0) {
				LM_INFO("found domain %.*s\n", rd->trees[i]->name.len, rd->trees[i]->name.s);
				return rd->trees[i]->tree;
			}
		}
	}
	LM_INFO("domain %s not found, add it\n", domain);
	if ((id = add_domain(domain)) < 0) {
		LM_ERR("could not add domain\n");
		return NULL;
	}
	if ((rt = create_route_tree(domain, id)) == NULL) {
		return NULL;
	}
	if ((rt->tree = create_route_tree_item()) == NULL) {
		return NULL;
	}
	if (add_route_tree(rd, rt) < 0) {
		LM_ERR("couldn't add route tree\n");
		destroy_route_tree(rt);
		return NULL;
	}
	LM_INFO("created route tree: %.*s, %i\n", rt->name.len, rt->name.s, rt->id);
	return rt->tree;
}
Ejemplo n.º 4
0
/*
	Parse a line of the configuration file.
	For each keyword recognised, perform appropriate handling.
	If the keyword is not recognised, print a message to syslog
	and continue.
	
	Returns
		0 success, or recoverable config file error
		non-zero serious system error, processing aborted
 */
static errcode_t
process_config_line (
	config_t * conf,
	char * line,
	config_file_context_t * context
)
{
	char * curr = line;
	char * word;
	
	word = get_next_word (curr, &curr);
	if (! word || word [0] == k_comment_char)
	{
		// Nothing interesting on this line
		return 0;
	}
	
	if (strcmp (word, k_keyword_domain) == 0)
	{
		word = get_next_word (curr, &curr);
		if (word)
		{
			int errcode = add_domain (conf, word);
			if (errcode)
			{
				// something badly wrong, bail
				return errcode;
			}
			
			if (get_next_word (curr, NULL))
			{
				LOG(PHIDGET_LOG_WARNING,
					"%s, line %d: ignored extra text found after domain",
					context->filename,
					context->linenum
				);
			}
		}
		else
		{
			LOG(PHIDGET_LOG_WARNING,
				"%s, line %d: no domain specified",
				context->filename,
				context->linenum
			);
		}
	}
	else
	{
		LOG(PHIDGET_LOG_WARNING,
			"%s, line %d: unknown keyword %s - skipping",
			context->filename,
			context->linenum,
			word
		);
	}
	
	return 0;
}
Ejemplo n.º 5
0
/**
 * Get the domain id from multiparam_t structure.
 *
 * @param _msg SIP message
 * @param mp carrier id as integer, pseudo-variable or AVP name of carrier
 * @return carrier id on success, -1 otherwise
 *
 */
int mp2domain_id(struct sip_msg * _msg, struct multiparam_t *mp) {
	int domain_id;
	struct usr_avp *avp;
	int_str avp_val;
	str tmp;

	/* TODO combine the redundant parts of the logic */
	switch (mp->type) {
	case MP_INT:
		return mp->u.n;
		break;
	case MP_AVP:
		avp = search_first_avp(mp->u.a.flags, mp->u.a.name, &avp_val, 0);
		if (!avp) {
			LM_ERR("cannot find AVP '%d'\n", mp->u.a.name);
			return -1;
		}
		if ((avp->flags&AVP_VAL_STR)==0) {
			return avp_val.n;
		}
		else {
			domain_id = add_domain(&avp_val.s);
			if (domain_id < 0) {
				LM_ERR("could not find domain '%.*s'\n", avp_val.s.len, avp_val.s.s);
				return -1;
			}
			return domain_id;
		}
		break;
	case MP_PVE:
		/* retrieve domain name from parameter */
		if (pv_printf_s(_msg, mp->u.p, &tmp)<0) {
			LM_ERR("cannot print the domain\n");
			return -1;
		}
		domain_id = add_domain(&tmp);
		if (domain_id < 0) {
			LM_ERR("could not find domain '%.*s'\n", tmp.len, tmp.s);
			return -1;
		}
		return domain_id;
	default:
		LM_ERR("invalid domain type\n");
		return -1;
	}
}
Ejemplo n.º 6
0
/**
 * fixes the module functions' parameters if it is a domain.
 * supports name string, and AVPs.
 *
 * @param param the parameter
 *
 * @return 0 on success, -1 on failure
 */
static int domain_fixup(void ** param) {
	pv_spec_t avp_spec;
	struct multiparam_t *mp;
	str s;

	mp = (struct multiparam_t *)pkg_malloc(sizeof(struct multiparam_t));
	if (mp == NULL) {
		LM_ERR("no more memory\n");
		return -1;
	}
	memset(mp, 0, sizeof(struct multiparam_t));

	s.s = (char *)(*param);
	s.len = strlen(s.s);

	if (s.s[0]!='$') {
		/* This is a name string */
		mp->type=MP_INT;

		/* get domain id */
		if ((mp->u.n = add_domain(&s)) < 0) {
			LM_ERR("could not add domain\n");
			pkg_free(mp);
			return -1;
		}
		pkg_free(*param);
		*param = (void *)mp;
	}
	else {
		/* This is a pseudo-variable */
		if (pv_parse_spec(&s, &avp_spec)==0) {
			LM_ERR("pv_parse_spec failed for '%s'\n", (char *)(*param));
			pkg_free(mp);
			return -1;
		}
		if (avp_spec.type==PVT_AVP) {
			/* This is an AVP - could be an id or name */
			mp->type=MP_AVP;
			if(pv_get_avp_name(0, &(avp_spec.pvp), &(mp->u.a.name), &(mp->u.a.flags))!=0) {
				LM_ERR("Invalid AVP definition <%s>\n", (char *)(*param));
				pkg_free(mp);
				return -1;
			}
		} else {
			mp->type=MP_PVE;
			if(pv_parse_format(&s, &(mp->u.p))<0) {
				LM_ERR("pv_parse_format failed for '%s'\n", (char *)(*param));
				pkg_free(mp);
				return -1;
			}
		}
	}
	*param = (void*)mp;

	return 0;
}
Ejemplo n.º 7
0
static void
add_domains_by_name (virConnectPtr conn, char **names, size_t n)
{
  size_t i;
  virDomainPtr dom;

  for (i = 0; i < n; ++i) {
    dom = virDomainLookupByName (conn, names[i]);
    if (dom)     /* transient errors are possible here, ignore them */
      add_domain (dom);
  }
}
Ejemplo n.º 8
0
static void
add_domains_by_id (virConnectPtr conn, int *ids, size_t n)
{
  size_t i;
  virDomainPtr dom;

  for (i = 0; i < n; ++i) {
    if (ids[i] != 0) {          /* RHBZ#538041 */
      dom = virDomainLookupByID (conn, ids[i]);
      if (dom)   /* transient errors are possible here, ignore them */
        add_domain (dom);
    }
  }
}
Ejemplo n.º 9
0
static errcode_t
default_config (config_t * conf)
{
	int i;
	for (i = 0; k_default_domains [i]; i++)
	{
		int errcode =
			add_domain (conf, k_default_domains [i]);
		if (errcode)
		{
			// Something has gone (badly) wrong - let's bail
			return errcode;
		}
	}
	
	return 0;
}
Ejemplo n.º 10
0
ret_code_t domain_proc(void)
{
	SaHpiDomainInfoT	info;
	SaHpiEntryIdT		entryid, nextentryid;
	SaHpiDrtEntryT		drtentry;
	SaErrorT		rv;
	SaHpiDomainIdT		id;
	SaHpiSessionIdT		sessionId;
	int			i, n, first;
	gpointer		ptr;
	Domain_t		*domain = (Domain_t *)NULL;
	Domain_t		*new_domain;
	term_def_t		*term;

	term = get_next_term();
	if (term == NULL) {
		printf("Domain list:\n");
		printf("    ID: %d   SessionId: %d", Domain->domainId,
			Domain->sessionId);
		rv = saHpiDomainInfoGet(Domain->sessionId, &info);
		if (rv == SA_OK) {
			print_text_buffer_text("    Tag: ",
				&(info.DomainTag), NULL, ui_print);
		};
		printf("\n");
		entryid = SAHPI_FIRST_ENTRY;
		first = 1;
		while (entryid != SAHPI_LAST_ENTRY) {
			rv = saHpiDrtEntryGet(Domain->sessionId, entryid,
				&nextentryid, &drtentry);
			if (rv != SA_OK) break;
			if (first) {
				first = 0;
				printf("        Domain Reference Table:\n");
			};
			printf("            ID: %d", drtentry.DomainId);
			entryid = nextentryid;
			rv = saHpiSessionOpen(drtentry.DomainId,
						&sessionId, NULL);
			if (rv != SA_OK) {
				printf("\n");
				continue;
			};
			rv = saHpiDomainInfoGet(sessionId, &info);
			if (rv == SA_OK) {
				print_text_buffer_text("    Tag: ",  &(info.DomainTag), NULL, ui_print);
			};
			saHpiSessionClose(sessionId);
			printf("\n");
		}
		return(HPI_SHELL_OK);
	};

	if (isdigit(term->term[0]))
		id = (int)atoi(term->term);
	else
		return HPI_SHELL_PARM_ERROR;
	n = g_slist_length(domainlist);
	for (i = 0; i < n; i++) {
		ptr = g_slist_nth_data(domainlist, i);
		if (ptr == (gpointer)NULL) break;
		domain = (Domain_t *)ptr;
		if (domain->domainId == id) break;
	};
	if (i >= n) {
		new_domain = (Domain_t *)malloc(sizeof(Domain_t));
		memset(new_domain, 0, sizeof(Domain_t));
		new_domain->domainId = id;
		if (add_domain(new_domain) < 0) {
			free(new_domain);
			printf("Can not open domain: %d\n", id);
			return HPI_SHELL_PARM_ERROR;
		};
		domain = new_domain;
	};
	Domain = domain;
	set_Subscribe(Domain, prt_flag);
	add_domain(Domain);
	return(HPI_SHELL_OK);
}
Ejemplo n.º 11
0
int libvirt_open() {
	conn = virConnectOpenReadOnly("xen:///");
	if(conn == NULL) {
	  printf("libvirt connection open error on uri \n"); 
	  return 0;
	}
	int n;
	n = virConnectNumOfDomains(conn);
	if(n < 0) {
		printf("Error reading number of domains \n");
		return -1;
	}

	int i;
	int *domids;

	domids = malloc(sizeof(int) * n);
	if(domids == 0) {
		printf("libvirt domain ids malloc failed");
		return -1;
	}
	n = virConnectListDomains(conn, domids, n);
	if(n < 0) {
		printf("Error reading list of domains \n");
		free(domids);
		return -1;
	}

	free_block_devices();
	free_interface_devices();
	free_domains();

	for (i = 0; i < n ; ++i) {
		virDomainPtr dom = NULL;
		const char *name;
		char *xml = NULL;
		xmlDocPtr xml_doc = NULL;
		xmlXPathContextPtr xpath_ctx = NULL;
		xmlXPathObjectPtr xpath_obj = NULL;
		int j;

		//printf("Publishing Domain Id : %d \n ", domids[i]);
		dom = virDomainLookupByID(conn, domids[i]);
		if(dom == NULL) {
			printf("Domain no longer active or moved away .. \n");
		}
		name = virDomainGetName(dom);
		//printf("Publishing Domain Name : %s \n ", name);
		if(name == NULL) {
			printf("Domain name not valid .. \n");
			goto cont;	
		}
		if(add_domain(dom) < 0) {
			printf("libvirt plugin malloc failed .. \n");
			goto cont;
		}
		xml = virDomainGetXMLDesc(dom, 0);
		if(!xml) {
			printf("Virt domain xml description error ..\n");
			goto cont;
		}
		//printf("Publishing XML : \n %s \n ", xml);

		xml_doc = xmlReadDoc((xmlChar *) xml, NULL, NULL, XML_PARSE_NONET);
		if(xml_doc == NULL) {
			printf("XML read doc error ..\n");
			goto cont;
		}

		xpath_ctx = xmlXPathNewContext(xml_doc);
		xpath_obj = xmlXPathEval((xmlChar *) "/domain/devices/disk/target[@dev]", xpath_ctx);
		if(xpath_obj == NULL || xpath_obj->type != XPATH_NODESET || xpath_obj->nodesetval == NULL) {
			goto cont;
		}

		for(j = 0; j < xpath_obj->nodesetval->nodeNr; ++j) {
			xmlNodePtr node;
			char *path = NULL;
			node = xpath_obj->nodesetval->nodeTab[j];
			if(!node) continue;
			path = (char *) xmlGetProp (node, (xmlChar *) "dev");
			if(!path) continue;
			add_block_device(dom, path);
		}
		xmlXPathFreeObject(xpath_obj);

		xpath_obj = xmlXPathEval((xmlChar *) "/domain/devices/interface/target[@dev]", xpath_ctx);
		if(xpath_obj == NULL || xpath_obj->type != XPATH_NODESET || xpath_obj->nodesetval == NULL) {
			goto cont;
		}

		for(j = 0; j < xpath_obj->nodesetval->nodeNr; ++j) {
			xmlNodePtr node;
			char *path = NULL;
			node = xpath_obj->nodesetval->nodeTab[j];
			if(!node) continue;
			path = (char *) xmlGetProp(node, (xmlChar *) "dev");
			if(!path) continue;
			add_interface_device(dom, path);
		}
		cont:
			if(xpath_obj) xmlXPathFreeObject(xpath_obj);
			if(xpath_ctx) xmlXPathFreeContext(xpath_ctx);
			if(xml_doc) xmlFreeDoc(xml_doc);
			if(xml) free(xml);
	}
	free(domids);
	return 0;
}
Ejemplo n.º 12
0
static int
refresh_lists (void)
{
    int n;

    n = virConnectNumOfDomains (conn);
    if (n < 0) {
        VIRT_ERROR (conn, "reading number of domains");
        return -1;
    }

    if (n > 0) {
        int i;
        int *domids;

        /* Get list of domains. */
        domids = malloc (sizeof (*domids) * n);
        if (domids == NULL) {
            ERROR (PLUGIN_NAME " plugin: malloc failed.");
            return -1;
        }

        n = virConnectListDomains (conn, domids, n);
        if (n < 0) {
            VIRT_ERROR (conn, "reading list of domains");
            sfree (domids);
            return -1;
        }

        free_block_devices ();
        free_interface_devices ();
        free_domains ();

        /* Fetch each domain and add it to the list, unless ignore. */
        for (i = 0; i < n; ++i) {
            virDomainPtr dom = NULL;
            const char *name;
            char *xml = NULL;
            xmlDocPtr xml_doc = NULL;
            xmlXPathContextPtr xpath_ctx = NULL;
            xmlXPathObjectPtr xpath_obj = NULL;
            int j;

            dom = virDomainLookupByID (conn, domids[i]);
            if (dom == NULL) {
                VIRT_ERROR (conn, "virDomainLookupByID");
                /* Could be that the domain went away -- ignore it anyway. */
                continue;
            }

            name = virDomainGetName (dom);
            if (name == NULL) {
                VIRT_ERROR (conn, "virDomainGetName");
                goto cont;
            }

            if (il_domains && ignorelist_match (il_domains, name) != 0)
                goto cont;

            if (add_domain (dom) < 0) {
                ERROR (PLUGIN_NAME " plugin: malloc failed.");
                goto cont;
            }

            /* Get a list of devices for this domain. */
            xml = virDomainGetXMLDesc (dom, 0);
            if (!xml) {
                VIRT_ERROR (conn, "virDomainGetXMLDesc");
                goto cont;
            }

            /* Yuck, XML.  Parse out the devices. */
            xml_doc = xmlReadDoc ((xmlChar *) xml, NULL, NULL, XML_PARSE_NONET);
            if (xml_doc == NULL) {
                VIRT_ERROR (conn, "xmlReadDoc");
                goto cont;
            }

            xpath_ctx = xmlXPathNewContext (xml_doc);

            /* Block devices. */
            xpath_obj = xmlXPathEval
                ((xmlChar *) "/domain/devices/disk/target[@dev]",
                 xpath_ctx);
            if (xpath_obj == NULL || xpath_obj->type != XPATH_NODESET ||
                xpath_obj->nodesetval == NULL)
                goto cont;

            for (j = 0; j < xpath_obj->nodesetval->nodeNr; ++j) {
                xmlNodePtr node;
                char *path = NULL;

                node = xpath_obj->nodesetval->nodeTab[j];
                if (!node) continue;
                path = (char *) xmlGetProp (node, (xmlChar *) "dev");
                if (!path) continue;

                if (il_block_devices &&
                    ignore_device_match (il_block_devices, name, path) != 0)
                    goto cont2;

                add_block_device (dom, path);
            cont2:
                if (path) xmlFree (path);
            }
            xmlXPathFreeObject (xpath_obj);

            /* Network interfaces. */
            xpath_obj = xmlXPathEval
                ((xmlChar *) "/domain/devices/interface[target[@dev]]",
                 xpath_ctx);
            if (xpath_obj == NULL || xpath_obj->type != XPATH_NODESET ||
                xpath_obj->nodesetval == NULL)
                goto cont;

            xmlNodeSetPtr xml_interfaces = xpath_obj->nodesetval;

            for (j = 0; j < xml_interfaces->nodeNr; ++j) {
                char *path = NULL;
                char *address = NULL;
                xmlNodePtr xml_interface;

                xml_interface = xml_interfaces->nodeTab[j];
                if (!xml_interface) continue;
                xmlNodePtr child = NULL;

                for (child = xml_interface->children; child; child = child->next) {
                    if (child->type != XML_ELEMENT_NODE) continue;

                    if (xmlStrEqual(child->name, (const xmlChar *) "target")) {
                        path = (char *) xmlGetProp (child, (const xmlChar *) "dev");
                        if (!path) continue;
                    } else if (xmlStrEqual(child->name, (const xmlChar *) "mac")) {
                        address = (char *) xmlGetProp (child, (const xmlChar *) "address");
                        if (!address) continue;
                    }
                }

                if (il_interface_devices &&
                    (ignore_device_match (il_interface_devices, name, path) != 0 ||
                     ignore_device_match (il_interface_devices, name, address) != 0))
                    goto cont3;

                add_interface_device (dom, path, address, j+1);
                cont3:
                    if (path) xmlFree (path);
                    if (address) xmlFree (address);
            }

        cont:
            if (xpath_obj) xmlXPathFreeObject (xpath_obj);
            if (xpath_ctx) xmlXPathFreeContext (xpath_ctx);
            if (xml_doc) xmlFreeDoc (xml_doc);
            sfree (xml);
        }

        sfree (domids);
    }

    return 0;
}
Ejemplo n.º 13
0
void mem_menu_create(struct menu *menu)
{
  /* initialize data */
  vector_init(&domains, sizeof(struct mem_domain));
  add_domain(0x80000000, 0x00C00000, "k0 rdram");
  add_domain(0xA0000000, 0x00C00000, "k1 rdram");
  add_domain(0xA3F00000, 0x00100000, "rdram regs");
  add_domain(0xA4000000, 0x00100000, "sp regs");
  add_domain(0xA4100000, 0x00100000, "dp com");
  add_domain(0xA4200000, 0x00100000, "dp span");
  add_domain(0xA4300000, 0x00100000, "mi regs");
  add_domain(0xA4400000, 0x00100000, "vi regs");
  add_domain(0xA4500000, 0x00100000, "ai regs");
  add_domain(0xA4600000, 0x00100000, "pi regs");
  add_domain(0xA4800000, 0x00100000, "si regs");
  add_domain(0xA8000000, 0x08000000, "cart dom2");
  add_domain(0xB0000000, 0x0FC00000, "cart dom1");
  add_domain(0xBFC00000, 0x000007C0, "pif rom");
  add_domain(0xBFC007C0, 0x00000040, "pif ram");
  /* initialize menus */
  menu_init(menu, MENU_NOVALUE, MENU_NOVALUE, MENU_NOVALUE);
  menu->selector = menu_add_submenu(menu, 0, 0, NULL, "return");
  {
    view_address = menu_add_intinput(menu, 0, 1, 16, 8, address_proc, NULL);
    struct menu_item *data_size = menu_add_option(menu, 9, 1,
                                                  "byte\0""halfword\0""word\0",
                                                  data_size_proc, NULL);
    menu_option_set(data_size, 2);
    view_data_size = 4;
    menu_add_button(menu, 18, 1, "<", prev_domain_proc, NULL);
    menu_add_button(menu, 20, 1, ">", next_domain_proc, NULL);
    view_domain_name = menu_add_static(menu, 22, 1, NULL, 0xC0C0C0);
    view_domain_name->text = malloc(32);
    struct gfx_texture *t_arrow = resource_get(RES_ICON_ARROW);
    view_pageup = menu_add_button_icon(menu, 0, 2, t_arrow, 0, 0xFFFFFF,
                                       page_up_proc, NULL);
    view_pagedown = menu_add_button_icon(menu, 2, 2, t_arrow, 1, 0xFFFFFF,
                                         page_down_proc, NULL);
    menu_add_static(menu, 9, 2, "0 1 2 3 4 5 6 7", 0xC0C0C0);
    for (int y = 0; y < MEM_VIEW_ROWS; ++y) {
      view_rows[y] = menu_add_static(menu, 0, 3 + y, NULL, 0xC0C0C0);
      view_rows[y]->text = malloc(9);
    }
    make_cells(menu);
    goto_domain(0);
  }
}