Exemple #1
0
void UpnpActionRequest_assign(UpnpActionRequest *p, const UpnpActionRequest *q)
{
	if (p != q) {
		UpnpActionRequest_set_ErrCode(p, UpnpActionRequest_get_ErrCode(q));
		UpnpActionRequest_set_Socket(p, UpnpActionRequest_get_Socket(q));
		UpnpActionRequest_set_ErrStr(p, UpnpActionRequest_get_ErrStr(q));
		UpnpActionRequest_set_ActionName(p, UpnpActionRequest_get_ActionName(q));
		UpnpActionRequest_set_DevUDN(p, UpnpActionRequest_get_DevUDN(q));
		UpnpActionRequest_set_ServiceID(p, UpnpActionRequest_get_ServiceID(q));
		UpnpActionRequest_set_ActionRequest(p, UpnpActionRequest_get_ActionRequest(q));
		UpnpActionRequest_set_ActionResult(p, UpnpActionRequest_get_ActionResult(q));
		UpnpActionRequest_set_CtrlPtIPAddr(p, UpnpActionRequest_get_CtrlPtIPAddr(q));
		UpnpActionRequest_set_SoapHeader(p, UpnpActionRequest_get_SoapHeader(q));
	}
}
Exemple #2
0
/*!
 * \brief Handles the SOAP action request. It checks the integrity of the SOAP
 * action request and gives the call back to the device application.
 */
static void handle_invoke_action(
	/*! [in] Socket info. */
	IN SOCKINFO *info,
	/*! [in] HTTP Request. */
	IN http_message_t *request,
	/*! [in] Name of the SOAP Action. */
	IN memptr action_name,
	/*! [in] Document containing the SOAP action request. */
	IN IXML_Document *xml_doc)
{
	char save_char;
	UpnpActionRequest *action = UpnpActionRequest_new();
	UpnpString *devUDN = UpnpString_new();
	UpnpString *serviceID = UpnpString_new();
	IXML_Document *actionRequestDoc = NULL;
	IXML_Document *actionResultDoc = NULL;
	Upnp_FunPtr soap_event_callback;
	void *cookie = NULL;
	int err_code;
	const char *err_str;

	/* null-terminate */
	save_char = action_name.buf[action_name.length];
	action_name.buf[action_name.length] = '\0';
	/* set default error */
	err_code = SOAP_INVALID_ACTION;
	err_str = Soap_Invalid_Action;
	/* get action node */
	if (get_action_node(xml_doc, action_name.buf, &actionRequestDoc) == -1)
		goto error_handler;
	/* get device info for action event */
	err_code = get_device_info(request,
				   0,
				   xml_doc,
				   info->foreign_sockaddr.ss_family,
				   devUDN,
				   serviceID,
				   &soap_event_callback, &cookie);

	if (err_code != UPNP_E_SUCCESS)
		goto error_handler;
	UpnpActionRequest_set_ErrCode(action, UPNP_E_SUCCESS);
	UpnpActionRequest_strcpy_ErrStr(action, "");
	UpnpActionRequest_strcpy_ActionName(action, action_name.buf);
	UpnpActionRequest_set_DevUDN(action, devUDN);
	UpnpActionRequest_set_ServiceID(action, serviceID);
	UpnpActionRequest_set_ActionRequest(action, actionRequestDoc);
	UpnpActionRequest_set_CtrlPtIPAddr(action, &info->foreign_sockaddr);
	UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__, "Calling Callback\n");
	soap_event_callback(UPNP_CONTROL_ACTION_REQUEST, action, cookie);
	err_code = UpnpActionRequest_get_ErrCode(action);
	if (err_code != UPNP_E_SUCCESS) {
		err_str = UpnpActionRequest_get_ErrStr_cstr(action);
		if (strlen(err_str) <= 0) {
			err_code = SOAP_ACTION_FAILED;
			err_str = Soap_Action_Failed;
		}
		goto error_handler;
	}
	/* validate, and handle action error */
	actionResultDoc = UpnpActionRequest_get_ActionResult(action);
	if (actionResultDoc == NULL) {
		err_code = SOAP_ACTION_FAILED;
		err_str = Soap_Action_Failed;
		goto error_handler;
	}
	/* send response */
	send_action_response(info, actionResultDoc, request);
	err_code = 0;

	/* error handling and cleanup */
error_handler:
	/* restore */
	action_name.buf[action_name.length] = save_char;
	if (err_code != 0)
		send_error_response(info, err_code, err_str, request);
	UpnpString_delete(serviceID);
	UpnpString_delete(devUDN);
	UpnpActionRequest_delete(action);
}