📄 osphttp.c
字号:
/**########################################################################*########################################################################*########################################################################** COPYRIGHT (c) 1998, 1999 by TransNexus, LLC * * This software contains proprietary and confidential information * of TransNexus, LLC. Except as may be set forth in the license * agreement under which this software is supplied, use, disclosure, * or reproduction is prohibited without the prior, express, written* consent of TransNexus, LLC. * * $Date: 2000/12/05 00:46:43 $** $Id: osphttp.c,v 1.1 2000/12/05 00:46:43 wbreu Exp $** $RCSfile: osphttp.c,v $** $Revision: 1.1 $** $Source: /cvsroot/vocal/contrib/OSPToolkit-2.5.2/src/osphttp.c,v $**#########################################################################*#########################################################################*#########################################################################*//* * osphttp.c */#include "osp.h"#include "osphttp.h"#include "ospsocket.h"#include "osplist.h"#include "ospcomm.h"#include "ospmsgque.h"#include "ospmsginfo.h"#include "ospconfig.h"#include "osputils.h"intOSPPHttpNew( OSPTCOMM *ospvComm, OSPTHTTP **ospvHttp){ int errorcode = OSPC_ERR_NO_ERROR; OSPM_DBGENTER(("ENTER: OSPPHttpNew()\n")); /* * create space for the new HTTP connection object */ OSPM_MALLOC(*ospvHttp, OSPTHTTP, sizeof(OSPTHTTP)); if (*ospvHttp != (OSPTHTTP *)OSPC_OSNULL) { /* * initialize HTTP connection object space */ OSPM_MEMSET(*ospvHttp, 0, sizeof(OSPTHTTP)); /* * initialize the HTTP connection object mutex */ OSPM_MUTEX_INIT((*ospvHttp)->Mutex, NULL, errorcode); if (errorcode != OSPC_ERR_NO_ERROR) { OSPPHttpDelete(ospvHttp); } /* * initialize the HTTP connection conditional variable */ OSPM_CONDVAR_INIT((*ospvHttp)->CondVar, OSPC_OSNULL, errorcode); if (errorcode != OSPC_ERR_NO_ERROR) { OSPPHttpDelete(ospvHttp); } /* * initialize the HTTP connection message queue list */ OSPPListNew((OSPTLIST *)&((*ospvHttp)->MsgInfoList)); /* * save the pointer to the Comm Mgr so that the communication * attribute fields (timeout, retrydelay, retrylimit, etc...) * can be accessed from within the HTTP connection i/o functions */ (*ospvHttp)->Comm = (void *)ospvComm; /* * initialize the Socket File Descriptor to -1. * This indicates that a connection has never been established. */ (*ospvHttp)->SockFd = OSPC_SOCK_INVALID; } OSPM_DBGEXIT(("EXIT : OSPPHttpNew()\n")); return errorcode;}OSPTSEC * OSPPHttpGetSecurity( OSPTHTTP *ospvHttp){ OSPM_DBGENTER(("ENTER: OSPPHttpGetSecurity()\n")); OSPM_DBGEXIT(("EXIT : OSPPHttpGetSecurity()\n")); return OSPPCommGetSecurity((OSPTCOMM *)ospvHttp->Comm);}voidOSPPHttpDelete( OSPTHTTP **ospvHttp){ int errorcode = OSPC_ERR_NO_ERROR; OSPM_DBGENTER(("ENTER: OSPPHttpDelete()\n")); if (*ospvHttp) { OSPM_CONDVAR_DESTROY((*ospvHttp)->CondVar, errorcode); OSPM_MUTEX_DESTROY((*ospvHttp)->Mutex, errorcode); (void)OSPPSockClose(OSPC_TRUE, &((*ospvHttp)->SockFd), &((*ospvHttp)->SSLSession)); } OSPM_FREE(*ospvHttp); *ospvHttp = OSPC_OSNULL; OSPM_DBGEXIT(("EXIT : OSPPHttpDelete()\n")); return;}staticintosppHttpBuildMsg( unsigned char **ospvHttpMsg, unsigned *ospvHttpMsgSz, unsigned char *ospvRequestMsg, unsigned ospvRequestSz, OSPTSVCPT *ospvSvcPt, unsigned char *ospvContentType, unsigned ospvContentTypeSz){ int headersz = 0, errorcode = OSPC_ERR_NO_ERROR; char *header = OSPC_OSNULL; OSPM_DBGENTER(("ENTER: osppHttpBuildMsg()\n")); /* * determine the maximum size of the HTTP header */ headersz = OSPM_STRLEN(ospvSvcPt->URI) + OSPM_STRLEN(ospvSvcPt->HostName) + ospvContentTypeSz + OSPM_STRLEN(OSPC_HTTP_HEADER_MSG_FMT) + 1; /* * create space for the header */ OSPM_MALLOC(header, char, headersz); if (header != OSPC_OSNULL) { /* * format the header with the information from the Service Point * structure */ OSPM_SPRINTF(header, OSPC_HTTP_HEADER_MSG_FMT, ospvSvcPt->URI, ospvSvcPt->HostName, ospvContentType, ospvRequestSz); /* * adjust headersz to be exact size */ headersz = OSPM_STRLEN(header); *ospvHttpMsgSz = headersz + ospvRequestSz; /* * create space for the entire message */ OSPM_MALLOC(*ospvHttpMsg, unsigned char, *ospvHttpMsgSz + 1); if (*ospvHttpMsg != OSPC_OSNULL) { /* Put a null character at the end */ OSPM_MEMSET(*ospvHttpMsg, 0, *ospvHttpMsgSz + 1); /* * copy in the header */ OSPM_MEMCPY(*ospvHttpMsg, header, headersz); /* * copy in the body */ OSPM_MEMCPY(((*ospvHttpMsg) + headersz), ospvRequestMsg, ospvRequestSz); /* * free the temporary header string */ OSPM_FREE(header); } } if (errorcode != OSPC_ERR_NO_ERROR) { errorcode = OSPC_ERR_HTTP_BAD_MESSAGE; OSPM_DBGERRORLOG(errorcode, "http message could not be built"); } OSPM_DBGEXIT(("EXIT : osppHttpBuildMsg()\n")); return errorcode;}staticvoidosppHttpRemoveConnection( OSPTHTTP *ospvHttp){ OSPTCOMM *comm = OSPC_OSNULL; int errorcode = OSPC_ERR_NO_ERROR; OSPM_DBGENTER(("ENTER: osppHttpRemoveConnection()\n")); comm = (OSPTCOMM *)ospvHttp->Comm; /* * acquire the comm mgr mutex so that we can modify * the http connection data exclusively */ if (comm != (OSPTCOMM *)OSPC_OSNULL) { OSPM_MUTEX_LOCK(comm->Mutex, errorcode); assert(errorcode == OSPC_ERR_NO_ERROR); /* * remove the connection from the http connection list */ (void)OSPPListRemoveSpecificItem((OSPTLIST *)&(comm->HttpConnList), ospvHttp); /* * decrement the number of http connections */ (void)OSPPCommDecrementHttpConnCount(comm); OSPM_MUTEX_UNLOCK(comm->Mutex, errorcode); assert(errorcode == OSPC_ERR_NO_ERROR); } OSPM_DBGEXIT(("EXIT : osppHttpRemoveConnection()\n")); return;}staticintosppHttpBuildAndSend( OSPTHTTP *ospvHttp, OSPTMSGINFO *ospvMsginfo){ int errorcode = OSPC_ERR_NO_ERROR; unsigned char *httpmsg = OSPC_OSNULL; unsigned httpmsgsz = 0; OSPM_DBGENTER(("ENTER: osppHttpBuildAndSend() ospHttp = <%lx>\n", (unsigned long)ospvHttp)); errorcode = osppHttpBuildMsg(&httpmsg, &httpmsgsz, ospvMsginfo->RequestMsg, ospvMsginfo->RequestSz, ospvHttp->ServicePoint, ospvMsginfo->ContentType, OSPM_STRLEN((const char *)ospvMsginfo->ContentType)); if (errorcode == OSPC_ERR_NO_ERROR) { OSPM_DBGNET(("MISC : osppHttpBuildAndSend() sending\n[%s]\n", httpmsg)); /* * send the new msg request to the Service * Point. place the response in the ospvMsginfo * structure. Also get the Content-Type and * related size for the MIME parser */ OSPPSockProcessRequest(ospvHttp, httpmsg, httpmsgsz, &(ospvMsginfo->ResponseMsg), &(ospvMsginfo->ResponseSz), &(ospvMsginfo->ContentType), &(ospvMsginfo->ContentSz), &errorcode); } if (httpmsg != OSPC_OSNULL) OSPM_FREE(httpmsg); OSPM_DBGEXIT(("EXIT : osppHttpBuildAndSend()\n")); return errorcode;}/* * monitors the message queue for new HTTP requests. * When a new request is placed on the HTTP message queue, the conditional * variable (CondVar) within the HTTP connection structure is signalled and * the number of transactions (NumberOfTransactions) will be incremented. * This function will awake and assign the request to an available HTTP * connection. Upon the handoff of the request, this function will return to * the wait condition until the next message queue request arrives or until * the HTTP connection persistence expires. * * returns void. */staticOSPTTHREADRETURNosppHttpSetupAndMonitor( void *ospvArg) /* In - HTTP pointer casted to a void */{ OSPTHTTP *httpconn = OSPC_OSNULL; OSPTMSGINFO *msginfo = OSPC_OSNULL; OSPTCOMM *comm = OSPC_OSNULL; int errorcode = OSPC_ERR_NO_ERROR, tmperror = OSPC_ERR_NO_ERROR; unsigned attempts = 0, retrylimit = 0, retrydelay = 0, persistancetimeout = 0; OSPTBOOL connected = OSPC_FALSE, rollover = OSPC_FALSE, do_forever = OSPC_TRUE; OSPM_DBGENTER(("ENTER: osppHttpSetupAndMonitor() ospHttp = <%lx>\n", (unsigned long)ospvArg)); httpconn = (OSPTHTTP *)ospvArg; while (do_forever) { OSPM_DBGNET(("MISC : osppHttpSetupAndMonitor() monitor start\n")); msginfo = (OSPTMSGINFO *)OSPC_OSNULL; comm = (OSPTCOMM *)httpconn->Comm; /* * acquire message queue mutex */ OSPM_MUTEX_LOCK(httpconn->Mutex, errorcode); assert(errorcode == OSPC_ERR_NO_ERROR); if (errorcode == OSPC_ERR_NO_ERROR) { /* * wait for conditional variable on the transaction count */ while (httpconn->NumberOfTransactions == 0 && errorcode != OSPC_ERR_OS_CONDVAR_TIMEOUT && (comm && !(comm->Flags & OSPC_COMM_HTTPSHUTDOWN_BIT))) { if (comm != (OSPTCOMM *)OSPC_OSNULL) (void)OSPPCommGetPersistence(comm, &persistancetimeout); OSPM_CONDVAR_TIMEDWAIT(httpconn->CondVar, httpconn->Mutex, persistancetimeout, errorcode); /* wbr: moved dbg code after call to wait */ OSPM_DBGNET(("MISC : osppHttpSetupAndMonitor() before timed wait. %d seconds, err=%d\n", persistancetimeout, errorcode)); /* wbr: comment out for now assert(errorcode == OSPC_ERR_NO_ERROR || errorcode == OSPC_ERR_OS_CONDVAR_TIMEOUT); */ } OSPM_DBGNET(("MISC : osppHttpSetupAndMonitor() triggered event occurred\n")); /* * see if the connection has timed out due to inactivity * (HttpPersistance). If the connection has timed out, * free up all the resources associated with this connection * and exit the thread gracefully. Also, if the provider has * been deleted and the Shutdown Flag has been set, shutdown this * connection. */ if ((httpconn->NumberOfTransactions == 0 && errorcode == OSPC_ERR_OS_CONDVAR_TIMEOUT) || (comm == (OSPTCOMM *)OSPC_OSNULL || (comm->Flags & OSPC_COMM_HTTPSHUTDOWN_BIT) == OSPC_COMM_HTTPSHUTDOWN_BIT)) { OSPM_DBGNET(("MISC : osppHttpSetupAndMonitor() remove connection requested\n")); osppHttpRemoveConnection(httpconn); break; } /* * get the msginfo item from the queue */ msginfo = (OSPTMSGINFO *)OSPPListFirst(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -