bool mupnp_http_server_start(mUpnpHttpServer *httpServer) { mupnp_log_debug_l4("Entering...\n"); if (httpServer->acceptThread != NULL) return false; httpServer->acceptThread = mupnp_thread_new(); mupnp_thread_setaction(httpServer->acceptThread, mupnp_http_server_thread); mupnp_thread_setuserdata(httpServer->acceptThread, httpServer); /**** Thanks for Makela Aapo (10/31/05) ****/ httpServer->clientThreads = mupnp_threadlist_new(); if (mupnp_thread_start(httpServer->acceptThread) == false) { mupnp_thread_delete(httpServer->acceptThread); httpServer->acceptThread = NULL; /**** Thanks for Makela Aapo (10/31/05) ****/ mupnp_threadlist_delete(httpServer->clientThreads); httpServer->clientThreads = NULL; return false; } mupnp_log_debug_l4("Leaving...\n"); return true; }
/** * Destroy the given control point * * @param ctrlPoint The control point struct to destroy */ void mupnp_controlpoint_delete(mUpnpControlPoint *ctrlPoint) { mupnp_log_debug_l4("Entering...\n"); mupnp_controlpoint_stop(ctrlPoint); /* Delete cached interfaces */ mupnp_net_interfacelist_delete(ctrlPoint->ifCache); /* Delete expiration handlers */ mupnp_thread_delete(ctrlPoint->expThread); mupnp_mutex_delete(ctrlPoint->expMutex); mupnp_cond_delete(ctrlPoint->expCond); /* Delete others */ mupnp_mutex_delete(ctrlPoint->mutex); mupnp_xml_nodelist_delete(ctrlPoint->deviceRootNodeList); mupnp_devicelist_delete(ctrlPoint->deviceList); mupnp_ssdp_serverlist_delete(ctrlPoint->ssdpServerList); mupnp_ssdpresponse_serverlist_delete(ctrlPoint->ssdpResServerList); mupnp_http_serverlist_delete(ctrlPoint->httpServerList); mupnp_string_delete(ctrlPoint->httpEventURI); mupnp_eventlistenerlist_delete(ctrlPoint->eventListeners); #ifdef MUPNP_HTTP_USE_PERSISTENT_CONNECTIONS mupnp_http_persistentconnection_clear(); #endif free(ctrlPoint); mupnp_log_debug_l4("Leaving...\n"); }
static void mupnp_service_notifyall_thread(mUpnpThread* thread) { mUpnpService* service; service = (mUpnpService*)mupnp_thread_getuserdata(thread); mupnp_service_notifyall(service, true); mupnp_thread_delete(thread); }
bool mupnp_ssdpresponse_server_stop(mUpnpSSDPResponseServer* server) { mupnp_log_debug_l4("Entering...\n"); if (server->recvThread != NULL) { mupnp_thread_stop(server->recvThread); mupnp_thread_delete(server->recvThread); server->recvThread = NULL; } mupnp_log_debug_l4("Leaving...\n"); return true; }
bool mupnp_http_server_stop(mUpnpHttpServer *httpServer) { mupnp_log_debug_l4("Entering...\n"); if (httpServer->acceptThread != NULL) { mupnp_thread_stop(httpServer->acceptThread); mupnp_thread_delete(httpServer->acceptThread); httpServer->acceptThread = NULL; } /**** Thanks for Makela Aapo (10/31/05) ****/ if (httpServer->clientThreads != NULL) { mupnp_threadlist_stop(httpServer->clientThreads); mupnp_threadlist_delete(httpServer->clientThreads); httpServer->clientThreads = NULL; } mupnp_log_debug_l4("Leaving...\n"); return true; }
bool mupnp_ssdpresponse_server_start(mUpnpSSDPResponseServer* server) { mupnp_log_debug_l4("Entering...\n"); if (server->recvThread != NULL) return false; server->recvThread = mupnp_thread_new(); mupnp_thread_setaction(server->recvThread, mupnp_ssdpresponse_server_thread); mupnp_thread_setuserdata(server->recvThread, server); if (mupnp_thread_start(server->recvThread) == false) { mupnp_thread_delete(server->recvThread); server->recvThread = NULL; return false; } return true; 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); }