CgSoapRequest *cg_soap_request_new() { CgSoapRequest *soapReq; cg_log_debug_l4("Entering...\n"); soapReq = (CgSoapRequest *)malloc(sizeof(CgSoapRequest)); if ( NULL != soapReq ) { soapReq->rootNodeList = cg_xml_nodelist_new(); soapReq->soapRes = cg_soap_response_new(); soapReq->httpReq = cg_http_request_new(); soapReq->isHttpReqCreated = TRUE; cg_http_request_setcontenttype(soapReq->httpReq, CG_SOAP_CONTENT_TYPE); cg_http_request_setmethod(soapReq->httpReq, CG_HTTP_POST); cg_soap_request_setuserdata(soapReq, NULL); } cg_log_debug_l4("Leaving...\n"); return soapReq; }
void cg_soap_request_clear(CgSoapRequest *soapReq) { cg_log_debug_l4("Entering...\n"); cg_xml_nodelist_clear(soapReq->rootNodeList); if (soapReq->isHttpReqCreated == TRUE) cg_http_request_delete(soapReq->httpReq); soapReq->httpReq = cg_http_request_new(); soapReq->isHttpReqCreated = TRUE; cg_http_request_setcontenttype(soapReq->httpReq, CG_SOAP_CONTENT_TYPE); cg_http_request_setmethod(soapReq->httpReq, CG_HTTP_POST); cg_log_debug_l4("Leaving...\n"); }
CgUpnpSSDPRequest *cg_upnp_ssdprequest_new() { CgUpnpSSDPRequest *ssdpReq; cg_log_debug_l4("Entering...\n"); ssdpReq = cg_http_request_new(); cg_http_request_seturi(ssdpReq, "*"); cg_http_request_setversion(ssdpReq, CG_HTTP_VER11); cg_http_request_setcontentlength(ssdpReq, 0); cg_log_debug_l4("Leaving...\n"); return ssdpReq; }
static void cg_http_server_clientthread(CgThread *thread) { CgHttpServerClientData *clientData; CgHttpServer *httpServer; CgSocket *clientSock; void *httpServerUserData; CgHttpRequest *httpReq; char *version = NULL; cg_log_debug_l4("Entering...\n"); clientData = (CgHttpServerClientData *)cg_thread_getuserdata(thread); httpServer = clientData->httpServer; clientSock = clientData->clientSock; httpServerUserData = cg_http_server_getuserdata(httpServer); httpReq = cg_http_request_new(); cg_http_request_setsocket(httpReq, clientSock); /**** Thanks for Makela Aapo (10/31/05) ****/ while (cg_http_request_read(httpReq, clientSock) == TRUE && cg_thread_isrunnable(thread) == TRUE) { /* Check some validity of the request */ version = cg_http_request_getversion(httpReq); if (cg_strcmp(version, CG_HTTP_VER11) == 0) { /* According to HTTP/1.1 spec, we must not tolerate HTTP/1.1 request without HOST-header */ if (cg_http_request_gethost(httpReq) == NULL) { cg_http_request_postbadrequest(httpReq); continue; } } if (httpServer->listener != NULL) { cg_http_request_setuserdata(httpReq, httpServerUserData); httpServer->listener(httpReq); } /* Close connection according to HTTP version and headers */ if (cg_strcmp(version, CG_HTTP_VER10) == 0) { /* Terminate connection after HTTP/1.0 request */ break; } /* We are having HTTP/1.1 or better => terminate, if requested */ if (cg_http_request_iskeepaliveconnection(httpReq) == FALSE) { break; } } cg_log_debug_s("Dropping HTTP client\n"); cg_http_request_delete(httpReq); cg_socket_close(clientSock); cg_socket_delete(clientSock); cg_http_server_clientdata_delete(clientData); cg_thread_setuserdata(thread, NULL); // This code frequently crashes. mutex lock referencing free'd memory. cg_http_server_lock(httpServer); cg_thread_remove(thread); cg_http_server_unlock(httpServer); cg_log_debug_l4("Leaving...\n"); cg_thread_delete(thread); }