/*! * \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); }
/*! * \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); }
/**************************************************************************** * 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 ); } }