示例#1
0
/****************************************************************************
*	Function :	get_var_name
*
*	Parameters :
*		IN IXML_Document *TempDoc :	Document containing variable request
*		OUT char* VarName :	Name of the state varible
*
*	Description :	This function finds the name of the state variable
*				asked in the SOAP request.
*
*	Return :	int
*		returns 0 if successful else returns -1.
*	Note :
****************************************************************************/
static UPNP_INLINE int
get_var_name( IN IXML_Document * TempDoc,
              OUT char *VarName )
{
    IXML_Node *EnvpNode = NULL;
    IXML_Node *BodyNode = NULL;
    IXML_Node *StNode = NULL;
    IXML_Node *VarNameNode = NULL;
    IXML_Node *VarNode = NULL;
    const DOMString StNodeName = NULL;
    const DOMString Temp = NULL;
    int ret_val = -1;

    // Got the Envelop node here
    EnvpNode = ixmlNode_getFirstChild( ( IXML_Node * ) TempDoc );
    if( EnvpNode == NULL ) {
        goto error_handler;
    }
    // Got Body here
    BodyNode = ixmlNode_getFirstChild( EnvpNode );
    if( BodyNode == NULL ) {
        goto error_handler;
    }
    // Got action node here
    StNode = ixmlNode_getFirstChild( BodyNode );
    if( StNode == NULL ) {
        goto error_handler;
    }
    //Test whether this is the action node
    StNodeName = ixmlNode_getNodeName( StNode );
    if( StNodeName == NULL || strstr( StNodeName,
                                      "QueryStateVariable" ) == NULL ) {
        goto error_handler;
    }

    VarNameNode = ixmlNode_getFirstChild( StNode );
    if( VarNameNode == NULL ) {
        goto error_handler;
    }

    VarNode = ixmlNode_getFirstChild( VarNameNode );
    Temp = ixmlNode_getNodeValue( VarNode );
    linecopy( VarName, Temp );

    UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__,
                "Received query for variable  name %s\n",
                VarName );

    ret_val = 0;            // success

error_handler:
    return ret_val;
}
示例#2
0
/*!
 * \brief Finds the name of the state variable asked in the SOAP request.
 *
 * \return 0 if successful else returns -1.
 */
static UPNP_INLINE int get_var_name(
	/*! [in] Document containing variable request. */
	IXML_Document *TempDoc,
	/*! [out] Name of the state varible. */
	char *VarName)
{
	IXML_Node *EnvpNode = NULL;
	IXML_Node *BodyNode = NULL;
	IXML_Node *StNode = NULL;
	IXML_Node *VarNameNode = NULL;
	IXML_Node *VarNode = NULL;
	const DOMString StNodeName = NULL;
	const DOMString Temp = NULL;
	int ret_val = -1;

	/* Got the Envelop node here */
	EnvpNode = ixmlNode_getFirstChild((IXML_Node *) TempDoc);
	if (EnvpNode == NULL)
		goto error_handler;
	/* Got Body here */
	BodyNode = ixmlNode_getFirstChild(EnvpNode);
	if (BodyNode == NULL)
		goto error_handler;
	/* Got action node here */
	StNode = ixmlNode_getFirstChild(BodyNode);
	if (StNode == NULL)
		goto error_handler;
	/* Test whether this is the action node */
	StNodeName = ixmlNode_getNodeName(StNode);
	if (StNodeName == NULL ||
	    strstr(StNodeName, "QueryStateVariable") == NULL)
		goto error_handler;
	VarNameNode = ixmlNode_getFirstChild(StNode);
	if (VarNameNode == NULL)
		goto error_handler;
	VarNode = ixmlNode_getFirstChild(VarNameNode);
	Temp = ixmlNode_getNodeValue(VarNode);
	linecopy(VarName, Temp);
	UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__,
		   "Received query for variable  name %s\n", VarName);

	/* success */
	ret_val = 0;

error_handler:
	return ret_val;
}
示例#3
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(
    int iface,
	/*! [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;
	IXML_Document *resp_node = NULL;
	struct Upnp_Action_Request action;
	Upnp_FunPtr soap_event_callback;
	void *cookie = NULL;
	int err_code;
	const char *err_str;

	action.ActionResult = NULL;
	/* 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, &resp_node) == -1)
		goto error_handler;
	/* get device info for action event */
	err_code = get_device_info(iface, request,
				   0,
				   xml_doc,
				   info->foreign_sockaddr.ss_family,
				   action.DevUDN,
				   action.ServiceID,
				   &soap_event_callback, &cookie);

	if (err_code != UPNP_E_SUCCESS)
		goto error_handler;
	namecopy(action.ActionName, action_name.buf);
	linecopy(action.ErrStr, "");
	action.ActionRequest = resp_node;
	action.ActionResult = NULL;
	action.ErrCode = UPNP_E_SUCCESS;
	action.CtrlPtIPAddr = info->foreign_sockaddr;
	UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__, "Calling Callback\n");
	soap_event_callback(UPNP_CONTROL_ACTION_REQUEST, &action, cookie);
	if (action.ErrCode != UPNP_E_SUCCESS) {
		if (strlen(action.ErrStr) <= 0) {
			err_code = SOAP_ACTION_FAILED;
			err_str = Soap_Action_Failed;
		} else {
			err_code = action.ErrCode;
			err_str = action.ErrStr;
		}
		goto error_handler;
	}
	/* validate, and handle action error */
	if (action.ActionResult == NULL) {
		err_code = SOAP_ACTION_FAILED;
		err_str = Soap_Action_Failed;
		goto error_handler;
	}
	/* send response */
	send_action_response(info, action.ActionResult, request);
	err_code = 0;

	/* error handling and cleanup */
error_handler:
	ixmlDocument_free(action.ActionResult);
	ixmlDocument_free(resp_node);
	/* restore */
	action_name.buf[action_name.length] = save_char;
	if (err_code != 0)
		send_error_response(info, err_code, err_str, request);
}
示例#4
0
/*!
 * \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(
    int iface,
	/*! [in] Socket info. */
	SOCKINFO *info,
	/*! [in] HTTP request. */
	http_message_t *request,
	/*! [in] Document containing the variable request SOAP message. */
	IXML_Document *xml_doc)
{
	Upnp_FunPtr soap_event_callback;
	void *cookie;
	char var_name[LINE_SIZE];
	struct Upnp_State_Var_Request variable;
	const char *err_str;
	int err_code;

	/* get var name */
	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(iface, request, 1, xml_doc,
				   info->foreign_sockaddr.ss_family,
				   variable.DevUDN,
				   variable.ServiceID,
				   &soap_event_callback, &cookie);
	if (err_code != 0) {
		send_error_response(info, SOAP_INVALID_VAR,
				    Soap_Invalid_Var, request);
		return;
	}
	linecopy(variable.ErrStr, "");
	variable.ErrCode = UPNP_E_SUCCESS;
	namecopy(variable.StateVarName, var_name);
	variable.CurrentVal = NULL;
	variable.CtrlPtIPAddr = 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 (variable.CurrentVal == NULL) {
		send_error_response(info, SOAP_INVALID_VAR, Soap_Invalid_Var,
				    request);
		return;
	}
	if (variable.ErrCode != UPNP_E_SUCCESS) {
		if (strlen(variable.ErrStr) > 0) {
			err_code = SOAP_INVALID_VAR;
			err_str = Soap_Invalid_Var;
		} else {
			err_code = variable.ErrCode;
			err_str = variable.ErrStr;
		}
		send_error_response(info, err_code, err_str, request);
		return;
	}
	/* send response */
	send_var_query_response(info, variable.CurrentVal, request);
	ixmlFreeDOMString(variable.CurrentVal);
}
示例#5
0
/****************************************************************************
*	Function :	handle_query_variable
*
*	Parameters :
*		IN SOCKINFO *info :	Socket info
*		IN http_message_t* request : HTTP request
*		IN IXML_Document *xml_doc :	Document containing the variable request
*									SOAP message
*
*	Description :	This action handles the SOAP requests to querry the
*				state variables. This functionality has been deprecated in
*				the UPnP V1.0 architecture
*
*	Return :	void
*
*	Note :
****************************************************************************/
static UPNP_INLINE void
handle_query_variable( IN SOCKINFO * info,
                       IN http_message_t * request,
                       IN IXML_Document * xml_doc )
{
    Upnp_FunPtr soap_event_callback;
    void *cookie;
    char var_name[LINE_SIZE];
    struct Upnp_State_Var_Request variable;
    const char *err_str;
    int err_code;

    // get var name
    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
    if( get_device_info( request, 1, xml_doc, variable.DevUDN,
                         variable.ServiceID,
                         &soap_event_callback, &cookie ) != 0 ) {
        send_error_response( info, SOAP_INVALID_VAR,
                             Soap_Invalid_Var, request );
        return;
    }

    linecopy( variable.ErrStr, "" );
    variable.ErrCode = UPNP_E_SUCCESS;
    namecopy( variable.StateVarName, var_name );
    variable.CurrentVal = NULL;
    variable.CtrlPtIPAddr = info->foreign_ip_addr;

    // 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( variable.CurrentVal == NULL ) {
        err_code = SOAP_ACTION_FAILED;
        err_str = Soap_Action_Failed;
        send_error_response( info, SOAP_INVALID_VAR,
                             Soap_Invalid_Var, request );
        return;
    }
    if( variable.ErrCode != UPNP_E_SUCCESS ) {
        if( strlen( variable.ErrStr ) > 0 ) {
            err_code = SOAP_INVALID_VAR;
            err_str = Soap_Invalid_Var;
        } else {
            err_code = variable.ErrCode;
            err_str = variable.ErrStr;
        }
        send_error_response( info, err_code, err_str, request );
        return;
    }
    // send response
    send_var_query_response( info, variable.CurrentVal, request );
    ixmlFreeDOMString( variable.CurrentVal );

}
示例#6
0
/****************************************************************************
*	Function :	handle_invoke_action
*
*	Parameters :
*		IN SOCKINFO *info :	Socket info
*		IN http_message_t* request : HTTP Request	
*		IN memptr action_name :	 Name of the SOAP Action
*		IN IXML_Document *xml_doc :	document containing the SOAP action 
*									request
*
*	Description :	This functions handle the SOAP action request. It checks 
*		the integrity of the SOAP action request and gives the call back to 
*		the device application.
*
*	Return : void
*
*	Note :
****************************************************************************/
static void
handle_invoke_action( IN SOCKINFO * info,
                      IN http_message_t * request,
                      IN memptr action_name,
                      IN IXML_Document * xml_doc )
{
    char save_char;
    IXML_Document *resp_node = NULL;
    struct Upnp_Action_Request action;
    Upnp_FunPtr soap_event_callback;
    void *cookie = NULL;
    int err_code;
    const char *err_str;

    action.ActionResult = NULL;

    // 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, &resp_node ) == -1 ) {
        goto error_handler;
    }
    // get device info for action event
    err_code = get_device_info( request, 0, xml_doc, action.DevUDN,
                                action.ServiceID, &soap_event_callback,
                                &cookie );

    if( err_code != UPNP_E_SUCCESS ) {
        goto error_handler;
    }

	/* for user agent probe support! by HouXB, 22Oct10 */
	ListNode *node;
	http_header_t *header;

	node = ListHead(&request->headers);
	while( node != NULL ) 
	{
		header = ( http_header_t * ) node->item;
		if (!strncmp(USER_AGENT, header->name.buf, strlen(USER_AGENT)))
		{
			int aLen = (int)header->value.length;
			sprintf(action.UserAgent, "%.*s", aLen, header->value.buf );

			if(aLen <NAME_SIZE)
			{
				action.UserAgent[aLen] = '\0';
			}
			else
			{
				action.UserAgent[NAME_SIZE-1] = '\0';
			}
			/*  
			printf("\n####\nuser Agent found!\nallow len is:%d\nlen is: %d\nagent is:%s\n####\n", 
				NAME_SIZE, aLen, action.UserAgent);
			*/
			
			break;			
		}			
		node = ListNext( &request->headers , node );
	} 	
	/*end  for user agent probe support! by HouXB, 22Oct10 */
	
    namecopy( action.ActionName, action_name.buf );
    linecopy( action.ErrStr, "" );
    action.ActionRequest = resp_node;
    action.ActionResult = NULL;
    action.ErrCode = UPNP_E_SUCCESS;
    action.CtrlPtIPAddr = info->foreign_ip_addr;

    UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__,
                         "Calling Callback\n" );

    soap_event_callback( UPNP_CONTROL_ACTION_REQUEST, &action, cookie );

    if( action.ErrCode != UPNP_E_SUCCESS ) {
        if( strlen( action.ErrStr ) <= 0 ) {
            err_code = SOAP_ACTION_FAILED;
            err_str = Soap_Action_Failed;
        } else {
            err_code = action.ErrCode;
            err_str = action.ErrStr;
        }
        goto error_handler;
    }
    // validate, and handle action error
    if( action.ActionResult == NULL ) {
        err_code = SOAP_ACTION_FAILED;
        err_str = Soap_Action_Failed;
        goto error_handler;
    }
    // send response
    send_action_response( info, action.ActionResult, request );

    err_code = 0;

    // error handling and cleanup
  error_handler:
    ixmlDocument_free( action.ActionResult );
    ixmlDocument_free( resp_node );
    action_name.buf[action_name.length] = save_char;    // restore
    if( err_code != 0 ) {
        send_error_response( info, err_code, err_str, request );
    }
}
示例#7
0
planet_mpcorb::planet_mpcorb(const std::string& line)
{
	std::string linecopy(line);
	boost::algorithm::to_lower(linecopy);
	array6D elem;
	std::string tmp;
	//read keplerian elements from MPCORB.DAT
	for (int i = 0; i < 6; ++i) {
		tmp.clear();
		tmp.append(&linecopy[mpcorb_format[i][0]],mpcorb_format[i][1]);
		boost::algorithm::trim(tmp);
		elem[i] = boost::lexical_cast<double>(tmp);
	}
	// Converting orbital elements to the dictatorial PaGMO units.
	elem[0] *= ASTRO_AU;
	for (int i = 2; i < 6; ++i) {
		elem[i] *= ASTRO_DEG2RAD;
	}

	// Deal with MPCORB data format
	tmp.clear();
	tmp.append(&linecopy[mpcorb_format[6][0]],mpcorb_format[6][1]);
	boost::algorithm::trim(tmp);
	kep_toolbox::epoch epoch(packed_date2epoch(tmp));

	// Extract absolute magnitude
	tmp.clear();
	tmp.append(&linecopy[mpcorb_format[8][0]],mpcorb_format[8][1]);
	boost::algorithm::trim(tmp);
	m_H = boost::lexical_cast<double>(tmp);

	// Extract number of observations
	tmp.clear();
	tmp.append(&linecopy[mpcorb_format[9][0]],mpcorb_format[9][1]);
	boost::algorithm::trim(tmp);

	m_n_observations = boost::lexical_cast<unsigned int>(tmp);

	// Extract number of oppositions
	tmp.clear();
	tmp.append(&linecopy[mpcorb_format[10][0]],mpcorb_format[10][1]);
	boost::algorithm::trim(tmp);

	m_n_oppositions = boost::lexical_cast<unsigned int>(tmp);

	// Extract the year of discovery (if only one observation is made this field will, instead, contain the Arc length in Days)
	tmp.clear();
	tmp.append(&linecopy[mpcorb_format[11][0]],mpcorb_format[11][1]);
	boost::algorithm::trim(tmp);

	m_year_of_discovery = boost::lexical_cast<unsigned int>(tmp);

	//Now we estimate the asteroid radius, safe_radius and gravity parametes with hyper simplified assumptions
	double radius = 1329000 * std::pow(10,-m_H * 0.2); // This is assuming an albedo of 0.25 (www.physics.sfasu.edu/astro/asteroids/sizemagnitude.html)
	double mu_planet = 4./3. * M_PI * std::pow(radius,3) * 2800 * ASTRO_CAVENDISH;

	// Record asteroid name.
	tmp.clear();
	tmp.append(&linecopy[mpcorb_format[7][0]],mpcorb_format[7][1]);
	boost::algorithm::trim(tmp);

	build_planet(epoch,elem,ASTRO_MU_SUN,mu_planet,radius,radius*1.1,tmp);
}