Exemplo n.º 1
0
epr_t *epr_copy(epr_t *epr)
{
	int i;
	Selector *p1;
	Selector *p2;
	epr_t *cpy_epr = NULL;
	if(epr == NULL)
		return cpy_epr;

	cpy_epr = u_malloc(sizeof(epr_t));
	if (epr && epr->address)
		cpy_epr->address = u_strdup(epr->address);

	cpy_epr->refparams.uri = u_strdup(epr->refparams.uri);
	cpy_epr->refparams.selectorset.count = epr->refparams.selectorset.count;
	cpy_epr->refparams.selectorset.selectors = u_malloc(sizeof(Selector)*
			epr->refparams.selectorset.count);

	p1 = epr->refparams.selectorset.selectors;
	p2 = cpy_epr->refparams.selectorset.selectors;
	for(i = 0; i < epr->refparams.selectorset.count; i++) {
		p2->name = u_strdup(p1->name);
		p2->type = p1->type;
		if(p1->type == 0)
			p2->value = u_strdup(p1->value);
		else
			p2->value = (char *)epr_copy((epr_t*)p1->value);
		p1++;
		p2++;
	}
	return cpy_epr;
}
Exemplo n.º 2
0
static int epr_add_selector(epr_t *epr, const char *name, selector_entry *selector)
 {
 	int i;
 	Selector *p;
	if(epr == NULL) return 0;
 	p = epr->refparams.selectorset.selectors;
	for(i = 0; i< epr->refparams.selectorset.count; i++) {
		if(p->name && ( strcmp(name, p->name) == 0 ) ) {
			return -1;
		}
		p++;
	}
	p = epr->refparams.selectorset.selectors;
	p = u_realloc(p, (epr->refparams.selectorset.count+1) * sizeof(Selector));
	if(p == NULL) return -1;
	p[epr->refparams.selectorset.count].name = u_strdup(name);
	p[epr->refparams.selectorset.count].type = selector->type;
	if(selector->type == 0) {
		if (selector->entry.text) {
			p[epr->refparams.selectorset.count].value = u_strdup(selector->entry.text);
		}
	} else {
		p[epr->refparams.selectorset.count].value = (char *)epr_copy(selector->entry.eprp);
	}

	epr->refparams.selectorset.selectors = p;
	epr->refparams.selectorset.count++;
	return 0;
 }
Exemplo n.º 3
0
void
key_value_copy(const key_value_t *from, key_value_t *to)
{
  if (from->key)
    to->key = u_strdup(from->key);
  else
    to->key = NULL;
  to->type = from->type;
  if (from->type == 0)
    to->v.text = u_strdup(from->v.text);
  else
    to->v.epr = epr_copy(from->v.epr);
}
Exemplo n.º 4
0
epr_t *epr_create(const char *uri, hash_t * selectors, const char *address)
{
	epr_t *epr = NULL;
	epr = u_malloc(sizeof(epr_t));
	if (address == NULL)
		epr->address = u_strdup(WSA_TO_ANONYMOUS);
	else
		epr->address = u_strdup(address);

	epr->refparams.uri = u_strdup(uri);

	if (selectors) {
		hnode_t        *hn;
		hscan_t         hs;
		Selector *p;
		selector_entry *entry;
		epr->refparams.selectorset.count = hash_count(selectors);
		epr->refparams.selectorset.selectors = u_malloc(sizeof(Selector)*
			epr->refparams.selectorset.count);

		p = epr->refparams.selectorset.selectors;
		hash_scan_begin(&hs, selectors);
		while ((hn = hash_scan_next(&hs))) {
			p->name = u_strdup((char *)hnode_getkey(hn));
			entry = (selector_entry *)hnode_get(hn);
			if(entry->type == 0) {
				p->type = 0;
				p->value = u_strdup(entry->entry.text);
				debug("key = %s value=%s",
					(char *) hnode_getkey(hn), p->value);
			}
			else {
				p->type = 1;
				p->value = (char *)epr_copy(entry->entry.eprp);
				debug("key = %s value=%p(nested epr)",
					(char *) hnode_getkey(hn), p->value);
			}
			p++;
		}
	} else {
		epr->refparams.selectorset.count  = 0;
		epr->refparams.selectorset.selectors  = NULL;
	}
	return epr;
}
Exemplo n.º 5
0
key_value_t *
key_value_create(const char *key, const char *text, const epr_t *epr, key_value_t *prealloc)
{
  if (prealloc == NULL)
    prealloc = (key_value_t *)u_malloc(sizeof(key_value_t));
  if (!prealloc) {
    debug("u_malloc() failed in key_value_create\n");
    return NULL;
  }
  if (key) /* might be NULL if only value is stored */
    prealloc->key = u_strdup(key);
  else
    prealloc->key = NULL;
  if (text) {
    prealloc->type = 0;
    prealloc->v.text = u_strdup(text);
  }
  else {
    prealloc->type = 1;
    prealloc->v.epr = epr_copy(epr);
  }
  return prealloc;
}
Exemplo n.º 6
0
static void test_serialize1(void)
{
	hash_t *selectors_filter = hash_create(HASHCOUNT_T_MAX, 0, 0);
	selector_entry *entry1 = NULL;
	entry1 = u_malloc(sizeof(selector_entry)*4);
	entry1[0].type = 0;
	entry1[0].entry.text = "OperatingSystemFilter0";
	entry1[1].type = 0;
        entry1[1].entry.text = "localhost.localdomain";
	entry1[2].type = 0;
        entry1[2].entry.text = "CIM_IndicationFilter";
	entry1[3].type = 0;
        entry1[3].entry.text = "CIM_ComputerSystem";
	hash_alloc_insert(selectors_filter, "Name", &entry1[0]);
	hash_alloc_insert(selectors_filter, "SystemName", &entry1[1]);
	hash_alloc_insert(selectors_filter, "CreationClassName", &entry1[2]);
	hash_alloc_insert(selectors_filter, "SystemCreationClassName", &entry1[3]);
	epr_t *epr_filter = epr_create("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationFilter", selectors_filter, NULL);
        if(epr_filter == NULL) {
                printf("epr_create filter failed!\n");
                return;
        }

	hash_t *selectors_handler = hash_create(HASHCOUNT_T_MAX, 0, 0);
	selector_entry *entry2 = u_malloc(sizeof(selector_entry)*4);
	entry2[0].type = 0;
        entry2[0].entry.text = "OperatingSystemHandler0";
        entry2[1].type = 0;
        entry2[1].entry.text = "localhost.localdomain";
        entry2[2].type = 0;
        entry2[2].entry.text = "CIM_IndicationHandlerCIMXML";
        entry2[3].type = 0;
        entry2[3].entry.text = "CIM_ComputerSystem";
	hash_alloc_insert(selectors_handler, "Name", &entry2[0]);
        hash_alloc_insert(selectors_handler, "SystemName", &entry2[1]);
        hash_alloc_insert(selectors_handler, "CreationClassName", &entry2[2]);
        hash_alloc_insert(selectors_handler, "SystemCreationClassName", &entry2[3]);
	epr_t *epr_handler = epr_create("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationHandlerCIMXML", selectors_handler, NULL);
	if(epr_handler == NULL) {
		printf("epr_create handler failed!\n");
		return;
	}

	hash_t *selectors_subscription =  hash_create(HASHCOUNT_T_MAX, 0, 0);
        selector_entry *entry3 = NULL;
        entry3 = u_malloc(sizeof(selector_entry)*2);
        entry3[0].type = 1;
        entry3[0].entry.eprp = epr_filter;
        entry3[1].type = 1;
        entry3[1].entry.eprp = epr_handler;
        hash_alloc_insert(selectors_subscription, "Filter", &entry3[1]);
	hash_alloc_insert(selectors_subscription, "Handler", &entry3[1]);
	epr_t *epr_subscription = epr_create("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationSubscription", selectors_subscription, NULL);
        if(epr_subscription == NULL) {
                printf("epr_create subscription failed!\n");
                return;
        }

	epr_t *epr_cpy = epr_copy(epr_subscription); //test epr_copy
	WsXmlDocH doc = ws_xml_create_envelope();
	WsXmlNodeH header = ws_xml_get_soap_header(doc);
	epr_serialize(header,NULL,NULL,epr_cpy,0);
	ws_xml_dump_doc(stdout, doc);

	epr_destroy(epr_filter);
	epr_destroy(epr_handler);
	epr_destroy(epr_subscription);
	epr_destroy(epr_cpy);
	hash_free(selectors_filter);
	hash_free(selectors_handler);
	hash_free(selectors_subscription);
	u_free(entry1);
	u_free(entry2);
	u_free(entry3);
	ws_xml_destroy_doc(doc);
	printf("\033[22;32mtest serialize epr successfully!\033[m\n\n");
}