示例#1
0
文件: soap_device.c 项目: rxwen/pupnp
/*!
 * \brief Handles the SOAP requests to querry the state variables.
 * This functionality has been deprecated in the UPnP V1.0 architecture.
 */
static UPNP_INLINE void handle_query_variable(
	IN SOCKINFO *info,
	IN http_message_t *request,
	IN IXML_Document *xml_doc)
{
	UpnpStateVarRequest *variable = UpnpStateVarRequest_new();
	Upnp_FunPtr soap_event_callback;
	void *cookie;
	char var_name[LINE_SIZE];
	const char *err_str;
	int err_code;

	if (get_var_name(xml_doc, var_name) != 0) {
		send_error_response(info, SOAP_INVALID_VAR,
				    Soap_Invalid_Var, request);
		return;
	}
	/* get info for event */
	err_code = get_device_info(request, 1, xml_doc,
		info->foreign_sockaddr.ss_family,
		(UpnpString *)UpnpStateVarRequest_get_DevUDN(variable),
		(UpnpString *)UpnpStateVarRequest_get_ServiceID(variable),
		&soap_event_callback, &cookie);
	if (err_code != 0) {
		send_error_response(info, SOAP_INVALID_VAR,
				    Soap_Invalid_Var, request);
		return;
	}
	UpnpStateVarRequest_set_ErrCode(variable, UPNP_E_SUCCESS);
	UpnpStateVarRequest_strcpy_StateVarName(variable, var_name);
	UpnpStateVarRequest_set_CtrlPtIPAddr(variable, &info->foreign_sockaddr);
	/* send event */
	soap_event_callback(UPNP_CONTROL_GET_VAR_REQUEST, variable, cookie);
	UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__,
		"Return from callback for var request\n");
	/* validate, and handle result */
	if (UpnpStateVarRequest_get_CurrentVal(variable) == NULL) {
		err_code = SOAP_ACTION_FAILED;
		err_str = Soap_Action_Failed;
		send_error_response(info, SOAP_INVALID_VAR, Soap_Invalid_Var,
				    request);
		return;
	}
	if (UpnpStateVarRequest_get_ErrCode(variable) != UPNP_E_SUCCESS) {
		if (UpnpString_get_Length(UpnpStateVarRequest_get_ErrStr(variable)) > 0) {
			err_code = SOAP_INVALID_VAR;
			err_str = Soap_Invalid_Var;
		} else {
			err_code = UpnpStateVarRequest_get_ErrCode(variable);
			err_str = UpnpStateVarRequest_get_ErrStr_cstr(variable);
		}
		send_error_response(info, err_code, err_str, request);

		return;
	}
	/* send response */
	send_var_query_response(info, UpnpStateVarRequest_get_CurrentVal(variable), request);
	UpnpStateVarRequest_delete(variable);
}
示例#2
0
int TvDeviceHandleGetVarRequest(UpnpStateVarRequest *cgv_event)
{
	unsigned int i = 0;
	int j = 0;
	int getvar_succeeded = 0;

	UpnpStateVarRequest_set_CurrentVal(cgv_event, NULL);

	ithread_mutex_lock(&TVDevMutex);

	for (i = 0; i < TV_SERVICE_SERVCOUNT; i++) {
		/* check udn and service id */
		const char *devUDN =
			UpnpString_get_String(UpnpStateVarRequest_get_DevUDN(cgv_event));
		const char *serviceID =
			UpnpString_get_String(UpnpStateVarRequest_get_ServiceID(cgv_event));
		if (strcmp(devUDN, tv_service_table[i].UDN) == 0 &&
		    strcmp(serviceID, tv_service_table[i].ServiceId) == 0) {
			/* check variable name */
			for (j = 0; j < tv_service_table[i].VariableCount; j++) {
				const char *stateVarName = UpnpString_get_String(
					UpnpStateVarRequest_get_StateVarName(cgv_event));
				if (strcmp(stateVarName,
					   tv_service_table[i].VariableName[j]) == 0) {
					getvar_succeeded = 1;
					UpnpStateVarRequest_set_CurrentVal(cgv_event,
						tv_service_table[i].VariableStrVal[j]);
					break;
				}
			}
		}
	}
	if (getvar_succeeded) {
		UpnpStateVarRequest_set_ErrCode(cgv_event, UPNP_E_SUCCESS);
	} else {
		SampleUtil_Print("Error in UPNP_CONTROL_GET_VAR_REQUEST callback:\n"
			"   Unknown variable name = %s\n",
			UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(cgv_event)));
		UpnpStateVarRequest_set_ErrCode(cgv_event, 404);
		UpnpStateVarRequest_strcpy_ErrStr(cgv_event, "Invalid Variable");
	}

	ithread_mutex_unlock(&TVDevMutex);

	return UpnpStateVarRequest_get_ErrCode(cgv_event) == UPNP_E_SUCCESS;
}