/************************************************************************ * Function: handle_request * * Parameters: * void *args - Request Message to be handled * * Description: * Receive the request and dispatch it for handling * * Return: void ************************************************************************/ static void handle_request( void *args ) { SOCKINFO info; int http_error_code; int ret_code; int major = 1; int minor = 1; http_parser_t parser; http_message_t *hmsg = NULL; int timeout = HTTP_DEFAULT_TIMEOUT; struct mserv_request_t *request = ( struct mserv_request_t * )args; int connfd = request->connfd; dlnaPrintf( DLNA_INFO, MSERV, __FILE__, __LINE__, "miniserver %d: READING\n", connfd ); //parser_request_init( &parser ); ////LEAK_FIX_MK hmsg = &parser.msg; if( sock_init_with_ip( &info, connfd, request->foreign_ip_addr, request->foreign_ip_port ) != DLNA_E_SUCCESS ) { free( request ); httpmsg_destroy( hmsg ); return; } // read ret_code = http_RecvMessage( &info, &parser, HTTPMETHOD_UNKNOWN, &timeout, &http_error_code ); if( ret_code != 0 ) { goto error_handler; } dlnaPrintf( DLNA_INFO, MSERV, __FILE__, __LINE__, "miniserver %d: PROCESSING...\n", connfd ); // dispatch http_error_code = dispatch_request( &info, &parser ); if( http_error_code != 0 ) { goto error_handler; } http_error_code = 0; error_handler: if( http_error_code > 0 ) { if( hmsg ) { major = hmsg->major_version; minor = hmsg->minor_version; } handle_error( &info, http_error_code, major, minor ); } dlnaPrintf( DLNA_INFO, MSERV, __FILE__, __LINE__, "miniserver %d: COMPLETE\n", connfd ); sock_destroy( &info, SD_BOTH ); //should shutdown completely httpmsg_destroy( hmsg ); free( request ); }
/*! * \brief Receive the request and dispatch it for handling. */ static void handle_request( /*! [in] Request Message to be handled. */ void *args) { SOCKINFO info; int http_error_code; int ret_code; int major = 1; int minor = 1; http_parser_t parser; http_message_t *hmsg = NULL; int timeout = HTTP_DEFAULT_TIMEOUT; struct mserv_request_t *request = (struct mserv_request_t *)args; SOCKET connfd = request->connfd; UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, "miniserver %d: READING\n", connfd ); /* parser_request_init( &parser ); */ /* LEAK_FIX_MK */ hmsg = &parser.msg; ret_code = sock_init_with_ip( &info, connfd, (struct sockaddr *)&request->foreign_sockaddr); if (ret_code != UPNP_E_SUCCESS) { free(request); httpmsg_destroy(hmsg); return; } /* read */ ret_code = http_RecvMessage( &info, &parser, HTTPMETHOD_UNKNOWN, &timeout, &http_error_code); if (ret_code != 0) { goto error_handler; } UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__, "miniserver %d: PROCESSING...\n", connfd); /* dispatch */ http_error_code = dispatch_request(&info, &parser); if (http_error_code != 0) { goto error_handler; } http_error_code = 0; error_handler: if (http_error_code > 0) { if (hmsg) { major = hmsg->major_version; minor = hmsg->minor_version; } handle_error(&info, http_error_code, major, minor); } sock_destroy(&info, SD_BOTH); httpmsg_destroy(hmsg); free(request); UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__, "miniserver %d: COMPLETE\n", connfd); }