bool mupnp_http_server_close(mUpnpHttpServer *httpServer) { mupnp_log_debug_l4("Entering...\n"); mupnp_http_server_stop(httpServer); if (httpServer->sock != NULL) { mupnp_socket_close(httpServer->sock); mupnp_socket_delete(httpServer->sock); httpServer->sock = NULL; } mupnp_log_debug_l4("Leaving...\n"); return true; }
BOOL mupnp_httpmu_socket_bind(mUpnpHttpMuSocket *sock, const char *mcastAddr, int port, const char *bindAddr) { mupnp_log_debug_l4("Entering...\n"); if (mupnp_socket_bind(sock, port, bindAddr, FALSE, TRUE) == FALSE) return FALSE; if (mupnp_socket_joingroup(sock, mcastAddr, bindAddr) == FALSE) { mupnp_socket_close(sock); return FALSE; } mupnp_log_debug_l4("Leaving...\n"); return TRUE; }
void mupnp_http_persistentconnection_delete(mUpnpHttpPersistentConnection *node) { mupnp_log_debug_l4("Entering...\n"); mupnp_string_delete(node->host); /* Terminate and delete connection according libcurl usage */ #if !defined(CG_HTTP_CURL) mupnp_socket_close((mUpnpSocket *)node->cacheData); mupnp_socket_delete((mUpnpSocket *)node->cacheData); #else curl_easy_cleanup((CURL *)node->cacheData); #endif free(node); mupnp_log_debug_l4("Leaving...\n"); }
static void mupnp_http_server_clientthread(mUpnpThread *thread) { mUpnpHttpServerClientData *clientData; mUpnpHttpServer *httpServer; mUpnpSocket *clientSock; void *httpServerUserData; mUpnpHttpRequest *httpReq; char *version = NULL; mupnp_log_debug_l4("Entering...\n"); clientData = (mUpnpHttpServerClientData *)mupnp_thread_getuserdata(thread); httpServer = clientData->httpServer; clientSock = clientData->clientSock; httpServerUserData = mupnp_http_server_getuserdata(httpServer); httpReq = mupnp_http_request_new(); mupnp_http_request_setsocket(httpReq, clientSock); /**** Thanks for Makela Aapo (10/31/05) ****/ while (mupnp_http_request_read(httpReq, clientSock) == true && mupnp_thread_isrunnable(thread) == true) { /* Check some validity of the request */ version = mupnp_http_request_getversion(httpReq); if (mupnp_strcmp(version, MUPNP_HTTP_VER11) == 0) { /* According to HTTP/1.1 spec, we must not tolerate HTTP/1.1 request without HOST-header */ if (mupnp_http_request_gethost(httpReq) == NULL) { mupnp_http_request_postbadrequest(httpReq); continue; } } if (httpServer->listener != NULL) { mupnp_http_request_setuserdata(httpReq, httpServerUserData); httpServer->listener(httpReq); } /* Close connection according to HTTP version and headers */ if (mupnp_strcmp(version, MUPNP_HTTP_VER10) == 0) { /* Terminate connection after HTTP/1.0 request */ break; } /* We are having HTTP/1.1 or better => terminate, if requested */ if (mupnp_http_request_iskeepaliveconnection(httpReq) == false) { break; } } mupnp_log_debug_s("Dropping HTTP client\n"); mupnp_http_request_delete(httpReq); mupnp_socket_close(clientSock); mupnp_socket_delete(clientSock); mupnp_http_server_clientdata_delete(clientData); mupnp_thread_setuserdata(thread, NULL); // This code frequently crashes. mutex lock referencing free'd memory. mupnp_http_server_lock(httpServer); mupnp_thread_remove(thread); mupnp_http_server_unlock(httpServer); mupnp_log_debug_l4("Leaving...\n"); mupnp_thread_delete(thread); }