コード例 #1
0
ファイル: eventsink.c プロジェクト: juergh/dash-sdk
static int print_events(WsXmlDocH indoc, void *data)
{
	FILE *f = stdout;
        const char *filename = output_file;
	struct tm *tm;
        time_t now;
        char timestr[128];
        char *log_msg;
        time(&now);
        tm = localtime(&now);
       // strftime(timestr, 128, "%b %e %T", tm);
	if (filename) {
		f = fopen(filename, "a+");
		if (f == NULL) {
			error("Could not open file for writing");
			return -1;
                }
        }

	if(f == stdout)
        	log_msg = u_strdup_printf("\t\t\033[22;32mAt %s received:\033[m \n\n",timestr);
	else
		log_msg = u_strdup_printf("At %s received:\n\n", timestr);
	        //fprintf(f, "%s", log_msg);

	       // ws_xml_dump_node_tree(f, ws_xml_get_doc_root(indoc));
			{
				WsXmlNodeH node;
				WsXmlNodeH class_node;
				char*	class_name;
				int		child_count;
				int		i;

				node		= ws_xml_get_soap_body (indoc);
				class_node	= ws_xml_get_child (node, 0, NULL, NULL);
				class_name  = ws_xml_get_node_local_name (class_node);

				printf ("\n%s\n", class_name);

				child_count	= ws_xml_get_child_count (class_node);
				for (i = 0; i < child_count; i++)
				{
					WsXmlNodeH	child_node;
					WsXmlAttrH	attr;
					char*		node_name;

					child_node	= ws_xml_get_child (class_node, i, NULL, NULL);
					attr		= ws_xml_get_node_attr (child_node, 0);
					node_name	= ws_xml_get_attr_value (attr);
					printf ("%-25s - %s\n", ws_xml_get_node_local_name (child_node), ws_xml_get_node_text (child_node));
				}
			}

	fflush(f);
	if (f != stdout) {
		fclose(f);
        }
        u_free(log_msg);
	return 0;
}
コード例 #2
0
static
void create_indication_event(WsXmlDocH indoc, WsSubscribeInfo *subsInfo, EventPoolOpSetH opset) {
	int count, i;
	int retval;
	WsNotificationInfoH notificationinfo = NULL;
	WsXmlNodeH node = ws_xml_get_doc_root(indoc);
	node = ws_xml_get_child(node, 0, NULL, CIMXML_MESSAGE);
	WsXmlNodeH tmp = ws_xml_get_child(node, 0, NULL, CIMXML_MULTIEXPREQ);
	if(tmp) {
		count = ws_xml_get_child_count(tmp);
		i = 0;
		while(i < count) {
			node = ws_xml_get_child(tmp, i,  NULL, CIMXML_SIMPLEEXPREQ);
			notificationinfo = create_notification_entity(subsInfo, node);
			if(notificationinfo == NULL) {
				i++;
				continue;
			}
			if(subsInfo->deliveryMode == WS_EVENT_DELIVERY_MODE_PULL)
				retval = opset->addpull(subsInfo->subsId, notificationinfo);
			else
				retval = opset->add(subsInfo->subsId, notificationinfo);
			if(retval) {
				u_free(notificationinfo->EventAction);
				ws_xml_destroy_doc(notificationinfo->EventContent);
				u_free(notificationinfo);
			}
			i++;
		}

	}
	else {
		tmp = ws_xml_get_child(node, 0, NULL, CIMXML_SIMPLEEXPREQ);
		notificationinfo = create_notification_entity(subsInfo, tmp);
		if(subsInfo->deliveryMode == WS_EVENT_DELIVERY_MODE_PULL)
			retval = opset->addpull(subsInfo->subsId, notificationinfo);
		else
			retval = opset->add(subsInfo->subsId, notificationinfo);
		if(retval) {
			u_free(notificationinfo->EventAction);
			ws_xml_destroy_doc(notificationinfo->EventContent);
			u_free(notificationinfo);
		}
	}

}
コード例 #3
0
static void cimxml_build_response_msg(WsXmlDocH indoc, WsXmlDocH *outdoc) {
	WsXmlDocH doc = NULL;
	WsXmlNodeH outnode = NULL;
	WsXmlNodeH innode = NULL;
	WsXmlNodeH temp = NULL;
	WsXmlNodeH temp2 = NULL;
	doc = ws_xml_create_doc(NULL, CIMXML_CIM);
	outnode = ws_xml_get_doc_root(doc);
	innode = ws_xml_get_doc_root(indoc);
//	char *value = ws_xml_get_node_attr(WsXmlNodeH node, int index)
	ws_xml_add_node_attr(outnode, NULL, CIMXML_CIMVERSION, "2.0");
	ws_xml_add_node_attr(outnode, NULL, CIMXML_DTDVERSION, "2.0");
	outnode = ws_xml_add_child(outnode, NULL, CIMXML_MESSAGE, NULL);
	innode = ws_xml_get_child(innode, 0, NULL, CIMXML_MESSAGE);
	int n = ws_xml_get_node_attr_count(innode);
	int i = 0;
	while(i < n) {
		WsXmlAttrH attr = ws_xml_get_node_attr(innode, i);
	 	char *name = ws_xml_get_attr_name(attr);
	 	char *value = ws_xml_get_attr_value(attr);
	 	ws_xml_add_node_attr(outnode, NULL, name, value);
	 	i++;
	}
	temp = ws_xml_get_child(innode, 0, NULL, CIMXML_SIMPLEEXPREQ);
	if(temp) {
		outnode = ws_xml_add_child(outnode, NULL, CIMXML_SIMPLEEXPRSP, NULL);
		outnode = ws_xml_add_child(outnode, NULL, CIMXML_EXPMETHODRESPONSE, NULL);
		ws_xml_add_node_attr(outnode, NULL, CIMXML_NAME, "ExportIndication");
		ws_xml_add_child(outnode, NULL, CIMXML_IRETURNVALUE, NULL);
	}
	else {
		temp = ws_xml_get_child(innode, 0, NULL, CIMXML_MULTIEXPREQ);
		outnode = ws_xml_add_child(outnode, NULL, CIMXML_MULTIEXPRSQ, NULL);
		n = ws_xml_get_child_count(temp);
		i = 0;
		while(i < n) {
			innode = ws_xml_get_child(temp, i, NULL, CIMXML_SIMPLEEXPREQ);
			temp2 = ws_xml_add_child(outnode, NULL, CIMXML_EXPMETHODRESPONSE, NULL);
			ws_xml_add_node_attr(temp2, NULL, CIMXML_NAME, "ExportIndication");
			ws_xml_add_child(temp2, NULL, CIMXML_IRETURNVALUE, NULL);
			i++;
		}
	}
	*outdoc = doc;
}
コード例 #4
0
ファイル: wsman-xml.c プロジェクト: photron/openwsman
/**
 * Count number of XML node children with same qualified name
 * (used to represent array elements)
 * @param parent XML node
 * @param nsUri Namespace URI
 * @param name children name to look for
 * @return Returns number of children of parent with this name
 * @brief Identical to ws_xml_get_child_count() if nsUri==NULL and name==NULL
 */
int 
ws_xml_get_child_count_by_qname(WsXmlNodeH parent, 
      const char *nsUri, const char *name)
{
	WsXmlNodeH node;
	int count;

	if (!parent)
	        return 0;
	if (nsUri == NULL && name == NULL) {
		return ws_xml_get_child_count(parent);
	}
	node = xml_parser_get_first_child(parent);
	count = 0;
	while (node != NULL) {
		if (ws_xml_is_node_qname(node, nsUri, name)) {
			count++;
		}
		node = xml_parser_get_next_child(node);
	}
	return count;
}
コード例 #5
0
ファイル: wsman-xml.c プロジェクト: photron/openwsman
WsXmlNodeH
ws_xml_add_child_sort(WsXmlNodeH node,
		 const char *nsUri, const char *localName, const char *val, int xmlescape)
{
	int i;
	WsXmlNodeH child, newNode = NULL;
	int count = ws_xml_get_child_count(node) ;
	if ( count == 0 ) {
		newNode = xml_parser_node_add(node, XML_LAST_CHILD, nsUri, localName, val, xmlescape);
	} else {
		for (i = 0; (child = ws_xml_get_child(node, i, NULL, NULL)) != NULL; i++) {
				char *name = ws_xml_get_node_local_name(child);
				if (strcmp(localName, name) < 0 ) {
					newNode = xml_parser_node_add(child, XML_ELEMENT_PREV, nsUri, localName, val, xmlescape);
					break;
				}
		}
		if (newNode == NULL) {
			newNode = xml_parser_node_add(node, XML_LAST_CHILD, nsUri, localName, val, xmlescape);
		}
	}
	return newNode;
}
コード例 #6
0
ファイル: wsman-epr.c プロジェクト: gyaneshvar/Openwsman
epr_t *epr_deserialize(WsXmlNodeH node, const char *ns,
		const char *epr_node_name, int embedded)
{
	int i;
	epr_t *epr = u_malloc(sizeof(epr_t));

	WsXmlNodeH eprnode = NULL;
	WsXmlNodeH refparamnode = NULL;
	WsXmlNodeH temp = NULL;
	WsXmlNodeH selectorsetnode = NULL;
	WsXmlAttrH attr = NULL;
	Selector *p = NULL;

	if(epr_node_name) {
		eprnode = ws_xml_get_child(node, 0, ns, epr_node_name);
		if(eprnode == NULL)
			goto CLEANUP;
	} else {
		eprnode = node;
	}

	if(embedded) {
		temp = ws_xml_get_child(eprnode, 0, XML_NS_ADDRESSING, WSA_ADDRESS);
	} else {
		temp = ws_xml_get_child(eprnode, 0, XML_NS_ADDRESSING, WSA_TO);
	}

	if(temp == NULL)
		goto CLEANUP;
	epr->address = u_strdup(ws_xml_get_node_text(temp));

	if(embedded) {
		refparamnode = ws_xml_get_child(eprnode, 0, XML_NS_ADDRESSING, WSA_REFERENCE_PARAMETERS);
	} else {
		refparamnode = node;
	}

	if(refparamnode == NULL)
		goto CLEANUP;

	temp = ws_xml_get_child(refparamnode, 0, XML_NS_WS_MAN, WSM_RESOURCE_URI);
	if(temp == NULL)
		goto CLEANUP;

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

	selectorsetnode = ws_xml_get_child(refparamnode, 0, XML_NS_WS_MAN, WSM_SELECTOR_SET);
	epr->refparams.selectorset.count = ws_xml_get_child_count(selectorsetnode);
	epr->refparams.selectorset.selectors = u_malloc(epr->refparams.selectorset.count *
		 sizeof(Selector));

	p = epr->refparams.selectorset.selectors;
	for(i = 0; i < epr->refparams.selectorset.count; i++) {
		temp = ws_xml_get_child(selectorsetnode, i, XML_NS_WS_MAN, WSM_SELECTOR);
		attr = ws_xml_find_node_attr(temp, NULL, "Name");
		if(attr) {
			p->name = u_strdup(ws_xml_get_attr_value(attr));
		}
		if(ws_xml_get_child(temp, 0, XML_NS_ADDRESSING, WSA_EPR)) {
			p->type = 1;
			p->value = (char *)epr_deserialize(temp, XML_NS_ADDRESSING, WSA_EPR, 1);
		} else {
			p->type = 0;
			p->value = u_strdup(ws_xml_get_node_text(temp));
		}
		p++;
	}

	return epr;
CLEANUP:
	u_free(epr);
	return NULL;

}