コード例 #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
ファイル: wsman-xml.c プロジェクト: photron/openwsman
/**
 * Duplicate an XML attribute
 * @param dstNode Destination XML node
 * @param srcNode Source Node
 */
void ws_xml_duplicate_attr(WsXmlNodeH dstNode, WsXmlNodeH srcNode)
{
	int i;
	WsXmlAttrH attr;
	for (i = 0; (attr = ws_xml_get_node_attr(srcNode, i)) != NULL; i++) {
		ws_xml_add_node_attr(dstNode,
				     ws_xml_get_attr_ns(attr),
				     ws_xml_get_attr_name(attr),
				     ws_xml_get_attr_value(attr));
	}
}
コード例 #3
0
ファイル: wsman-xml.c プロジェクト: photron/openwsman
char *ws_xml_find_attr_value(WsXmlNodeH node, const char *ns,
			     const char *attrName)
{
	char *val = NULL;
	WsXmlAttrH attr = ws_xml_find_node_attr(node, ns, attrName);

	if (attr)
		val = ws_xml_get_attr_value(attr);

	return val;
}
コード例 #4
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;
}
コード例 #5
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;

}
コード例 #6
0
static WsNotificationInfoH
create_notification_entity(WsSubscribeInfo *subsInfo, WsXmlNodeH node)
{
	char *classname = NULL;
	char *class_namespace = NULL;
	WsXmlNodeH indicationnode = NULL;
	WsNotificationInfoH notificationinfo = NULL;
	notificationinfo = u_zalloc(sizeof(*notificationinfo));
	if (notificationinfo == NULL) {
		return NULL;
	}
	WsXmlNodeH instance = ws_xml_get_child(node, 0, NULL, CIMXML_EXPMETHODCALL);
	if (instance == NULL) {
		u_free(notificationinfo);
		return NULL;
	}
	instance = ws_xml_get_child(instance, 0, NULL, CIMXML_EXPPARAMVALUE);
	if (instance == NULL) {
		u_free(notificationinfo);
		return NULL;
	}
	instance = ws_xml_get_child(instance, 0, NULL, CIMXML_INSTANCE);
	if (instance == NULL) {
		u_free(notificationinfo);
		return NULL;
	}
	WsXmlAttrH attr = ws_xml_find_node_attr(instance, NULL, CIMXML_CLASSNAME);
	if (attr) {
		classname = ws_xml_get_attr_value(attr);
		class_namespace = get_cim_indication_namespace(subsInfo, classname);
		notificationinfo->EventAction = u_strdup_printf("%s/%s", class_namespace, classname);
	}
	notificationinfo->EventContent = ws_xml_create_doc(notificationinfo->EventAction, classname);
	indicationnode = ws_xml_get_doc_root(notificationinfo->EventContent);
    //Parse "PROPERTY"
    int n = 0;
    while ( (node = ws_xml_get_child(instance, n++, NULL, CIMXML_PROPERTY)) ) {
        attr = ws_xml_find_node_attr(node, NULL, CIMXML_NAME);
        char *property = NULL;
        char *value = NULL;
        if ( attr ) {
            property = ws_xml_get_attr_value(attr);
        }
        value = ws_xml_get_node_text(node);
        ws_xml_add_child(indicationnode, notificationinfo->EventAction, property, value);
    }
 
    //Parse "PROPERTY.ARRAY"
    n = 0;
    while ( (node = ws_xml_get_child(instance, n++, NULL, CIMXML_PROPERTYARRAY)) ) {
        attr = ws_xml_find_node_attr(node, NULL, CIMXML_NAME);
        char *property = NULL;
        if ( attr ) {
            property = ws_xml_get_attr_value(attr);
            WsXmlNodeH valarraynode = ws_xml_get_child(node, 0, NULL, CIMXML_VALUEARRAY);
            if ( valarraynode ) {
                int m = 0;
                WsXmlNodeH valnode = NULL;
                while ( (valnode = ws_xml_get_child(valarraynode, m++, NULL, CIMXML_VALUE)) ) {
                    char *value = ws_xml_get_node_text(valnode);
                    ws_xml_add_child(indicationnode, notificationinfo->EventAction, property, value);
                }
            }
        }
    }
	if (class_namespace)
		u_free(class_namespace);
	return notificationinfo;
}
コード例 #7
0
ファイル: wsman-dispatcher.c プロジェクト: juergh/dash-sdk
/**
 * Check for duplicate Message ID
 * @param op operation
 * @return status
 */
static int
check_unsupported_features(op_t * op)
{
	WsXmlNodeH enumurate;
	WsXmlNodeH subscribe;
	WsXmlNodeH header = wsman_get_soap_header_element( op->in_doc, NULL, NULL);
	WsXmlNodeH body = ws_xml_get_soap_body(op->in_doc);
	int retVal = 0;
	WsXmlNodeH n, m, k;
	char *resource_uri = NULL, *mu = NULL;
	WsXmlAttrH attr = NULL;


	n = ws_xml_get_child(header, 0, XML_NS_ADDRESSING, WSA_FAULT_TO);
	if (n != NULL) {
		retVal = 1;
		generate_op_fault(op, WSMAN_UNSUPPORTED_FEATURE,
					WSMAN_DETAIL_ADDRESSING_MODE);
		goto DONE;
	}
	n = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_LOCALE);
	if (n != NULL) {
		debug("Locale header found");
		mu = ws_xml_find_attr_value(n, XML_NS_SOAP_1_2,
					    SOAP_MUST_UNDERSTAND);
		if (mu != NULL && strcmp(mu, "true") == 0) {
			retVal = 1;
			generate_op_fault(op,
						WSMAN_UNSUPPORTED_FEATURE,
						WSMAN_DETAIL_LOCALE);
			goto DONE;
		}
	}
#if 0
	n = ws_xml_get_child(header, 0, XML_NS_WS_MAN,
			     WSM_FRAGMENT_TRANSFER);
	if (n != NULL) {
		debug("FragmentTransfer header found");
		mu = ws_xml_find_attr_value(n, XML_NS_SOAP_1_2,
					    SOAP_MUST_UNDERSTAND);
		if (mu != NULL && strcmp(mu, "true") == 0) {
			retVal = 1;
			generate_op_fault(op,
						WSMAN_UNSUPPORTED_FEATURE,
						WSMAN_DETAIL_FRAGMENT_LEVEL_ACCESS);
			goto DONE;
		}
	}
#endif
	enumurate = ws_xml_get_child(body, 0, XML_NS_ENUMERATION,
			     WSENUM_ENUMERATE);
	if (enumurate) {

	n = ws_xml_get_child(enumurate, 0, XML_NS_ENUMERATION,
			     WSENUM_END_TO);
	if (n != NULL) {
		retVal = 1;
		generate_op_fault(op, WSMAN_UNSUPPORTED_FEATURE,
					WSMAN_DETAIL_ADDRESSING_MODE);
	}
	n = ws_xml_get_child(enumurate, 0, XML_NS_ENUMERATION,
			     WSENUM_FILTER);
	m = ws_xml_get_child(enumurate, 0, XML_NS_WS_MAN, WSM_FILTER);
	if (n != NULL && m != NULL) {
		retVal = 1;
		generate_op_fault(op, WSEN_CANNOT_PROCESS_FILTER, 0);
		goto DONE;
	} else if (n || m) {
		char *dia = NULL;
		if (n) {
			dia = ws_xml_find_attr_value(n, NULL, WSM_DIALECT);
		} else if (m) {
			dia = ws_xml_find_attr_value(m, NULL, WSM_DIALECT);
		}
		if (dia)
			retVal = check_supported_dialect(dia);
		else
			retVal = check_supported_dialect (WSM_XPATH_FILTER_DIALECT);

		if (retVal) {
			retVal = 1;
			generate_op_fault(op, WSEN_FILTER_DIALECT_REQUESTED_UNAVAILABLE,
						0);
			goto DONE;
			}
	}
	k = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_RESOURCE_URI);
	if (k)
		resource_uri = ws_xml_get_node_text(k);
	if (resource_uri &&
	    (strcmp(resource_uri, CIM_ALL_AVAILABLE_CLASSES) == 0)) {
		if (!n && !m) {
			retVal = 1;
			generate_op_fault(op, WSMAN_UNSUPPORTED_FEATURE,
						WSMAN_DETAIL_FILTERING_REQUIRED);
			goto DONE;
		}

	}
	}
	subscribe = ws_xml_get_child(body, 0, XML_NS_EVENTING, WSEVENT_SUBSCRIBE);
	if(subscribe) {
	/*	n = ws_xml_get_child(subscribe, 0, XML_NS_EVENTING, WSEVENT_ENDTO);
		if(n) {
			retVal = 1;
			generate_op_fault(op, WSMAN_UNSUPPORTED_FEATURE,
					WSMAN_DETAIL_ADDRESSING_MODE);
			goto DONE;
		}
	*/	n = ws_xml_get_child(subscribe, 0, XML_NS_EVENTING, WSEVENT_DELIVERY);
		if(n == NULL) {
			retVal = 1;
			generate_op_fault(op, WSE_INVALID_MESSAGE, 0);
			goto DONE;
		}
		attr = ws_xml_find_node_attr(n, NULL,WSEVENT_DELIVERY_MODE);
		if(attr) {
			mu = ws_xml_get_attr_value(attr);
			if (strcasecmp(mu, WSEVENT_DELIVERY_MODE_PUSH) &&
				strcasecmp(mu, WSEVENT_DELIVERY_MODE_PUSHWITHACK) &&
				strcasecmp(mu, WSEVENT_DELIVERY_MODE_EVENTS) &&
				strcasecmp(mu, WSEVENT_DELIVERY_MODE_PULL)) {
				debug("Unsupported delivery mode : %s",ws_xml_get_attr_value(attr));
				retVal = 1;
				generate_op_fault(op, WSE_DELIVERY_MODE_REQUESTED_UNAVAILABLE, 0);
				goto DONE;
			}
		}
		m = ws_xml_get_child(n, 0, XML_NS_WS_MAN, WSM_CONNECTIONRETRY);
		if(m) {
			retVal = 1;
			generate_op_fault(op, WSMAN_UNSUPPORTED_FEATURE, WSMAN_DETAIL_DELIVERY_RETRIES);
			goto DONE;
		}
	}
DONE:
	return retVal;
}