/*! * \brief Retrives all the information needed to process the incoming SOAP * request. It finds the device and service info and also the callback * function to hand-over the request to the device application. * * \return UPNP_E_SUCCESS if successful else returns appropriate error. */ static int get_device_info( int iface, /*! [in] HTTP request. */ http_message_t *request, /*! [in] flag for a querry. */ int isQuery, /*! [in] Action request document. */ IXML_Document *actionDoc, /*! [in] . */ int AddressFamily, /*! [out] Device UDN string. */ OUT char device_udn[LINE_SIZE], /*! [out] Service ID string. */ char service_id[LINE_SIZE], /*! [out] callback function of the device application. */ Upnp_FunPtr *callback, /*! [out] cookie stored by device application. */ void **cookie) { struct Handle_Info *device_info; int device_hnd; service_info *serv_info; char save_char; /* error by default */ int ret_code = -1; const char *control_url; char *actionName = NULL; /* null-terminate pathquery of url */ control_url = request->uri.pathquery.buff; save_char = control_url[request->uri.pathquery.size]; ((char *)control_url)[request->uri.pathquery.size] = '\0'; HandleLock(); if (GetDeviceHandleInfo(iface, AddressFamily, &device_hnd, &device_info) != HND_DEVICE) goto error_handler; serv_info = FindServiceControlURLPath( &device_info->ServiceTable, control_url); if (!serv_info) goto error_handler; if (isQuery) { ret_code = check_soap_action_header(request, QUERY_STATE_VAR_URN, &actionName); if (ret_code != UPNP_E_SUCCESS && ret_code != UPNP_E_OUTOF_MEMORY) { ret_code = UPNP_E_INVALID_ACTION; goto error_handler; } /* check soap body */ ret_code = check_soap_body(actionDoc, QUERY_STATE_VAR_URN, actionName); free(actionName); if (ret_code != UPNP_E_SUCCESS) goto error_handler; } else { ret_code = check_soap_action_header(request, serv_info->serviceType, &actionName); if (ret_code != UPNP_E_SUCCESS && ret_code != UPNP_E_OUTOF_MEMORY) { ret_code = UPNP_E_INVALID_SERVICE; goto error_handler; } /* check soap body */ ret_code = check_soap_body(actionDoc, serv_info->serviceType, actionName); free(actionName); if (ret_code != UPNP_E_SUCCESS) { ret_code = UPNP_E_INVALID_SERVICE; goto error_handler; } } namecopy(service_id, serv_info->serviceId); namecopy(device_udn, serv_info->UDN); *callback = device_info->Callback; *cookie = device_info->Cookie; ret_code = 0; error_handler: /* restore */ ((char *)control_url)[request->uri.pathquery.size] = save_char; HandleUnlock(); return ret_code; }
/**************************************************************************** * Function : get_device_info * * Parameters : * IN http_message_t* request : HTTP request * IN int isQuery : flag for a querry * IN IXML_Document *actionDoc : action request document * OUT char device_udn[LINE_SIZE] : Device UDN string * OUT char service_id[LINE_SIZE] : Service ID string * OUT Upnp_FunPtr *callback : callback function of the device * application * OUT void** cookie : cookie stored by device application * * Description : This function retrives all the information needed to * process the incoming SOAP request. It finds the device and service info * and also the callback function to hand-over the request to the device * application. * * Return : int * UPNP_E_SUCCESS if successful else returns appropriate error * * Note : ****************************************************************************/ static int get_device_info( IN http_message_t * request, IN int isQuery, IN IXML_Document * actionDoc, OUT char device_udn[LINE_SIZE], OUT char service_id[LINE_SIZE], OUT Upnp_FunPtr * callback, OUT void **cookie ) { struct Handle_Info *device_info; int device_hnd; service_info *serv_info; char save_char; int ret_code = -1; // error by default const char *control_url; char *actionName = NULL; // null-terminate pathquery of url control_url = request->uri.pathquery.buff; save_char = control_url[request->uri.pathquery.size]; ((char *)control_url)[request->uri.pathquery.size] = '\0'; HandleLock(); if( GetDeviceHandleInfo( &device_hnd, &device_info ) != HND_DEVICE ) { goto error_handler; } if( ( serv_info = FindServiceControlURLPath( &device_info->ServiceTable, control_url ) ) == NULL ) { goto error_handler; } if( isQuery ) { ret_code = check_soap_action_header( request, QUERY_STATE_VAR_URN, &actionName ); if( ( ret_code != UPNP_E_SUCCESS ) && ( ret_code != UPNP_E_OUTOF_MEMORY ) ) { ret_code = UPNP_E_INVALID_ACTION; goto error_handler; } //check soap body ret_code = check_soap_body( actionDoc, QUERY_STATE_VAR_URN, actionName ); free( actionName ); if( ret_code != UPNP_E_SUCCESS ) { goto error_handler; } } else { ret_code = check_soap_action_header( request, serv_info->serviceType, &actionName ); if( ( ret_code != UPNP_E_SUCCESS ) && ( ret_code != UPNP_E_OUTOF_MEMORY ) ) { ret_code = UPNP_E_INVALID_SERVICE; goto error_handler; } //check soap body ret_code = check_soap_body( actionDoc, serv_info->serviceType, actionName ); free( actionName ); if( ret_code != UPNP_E_SUCCESS ) { ret_code = UPNP_E_INVALID_SERVICE; goto error_handler; } } namecopy( service_id, serv_info->serviceId ); namecopy( device_udn, serv_info->UDN ); *callback = device_info->Callback; *cookie = device_info->Cookie; ret_code = 0; error_handler: ((char *)control_url)[request->uri.pathquery.size] = save_char; // restore HandleUnlock(); return ret_code; }