summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--runtime/netstrm.c7
-rw-r--r--runtime/netstrm.h6
-rw-r--r--runtime/nsd.h3
-rw-r--r--runtime/nsd_gtls.c91
-rw-r--r--runtime/nsd_ptcp.c28
-rw-r--r--runtime/nsdsel_gtls.c20
-rw-r--r--runtime/nsdsel_ptcp.c2
-rw-r--r--runtime/nssel.c2
-rw-r--r--runtime/obj-types.h4
-rw-r--r--tcpsrv.c2
10 files changed, 135 insertions, 30 deletions
diff --git a/runtime/netstrm.c b/runtime/netstrm.c
index 5e073899..be754aae 100644
--- a/runtime/netstrm.c
+++ b/runtime/netstrm.c
@@ -68,13 +68,6 @@ BEGINobjDestruct(netstrm) /* be sure to specify the object type also in END and
CODESTARTobjDestruct(netstrm)
if(pThis->pDrvrData != NULL)
iRet = pThis->Drvr.Destruct(&pThis->pDrvrData);
-
- /* driver can only be released after all data has been destructed */
- if(pThis->Drvr.ifIsLoaded == 1) {
- obj.ReleaseObj(__FILE__, pThis->pDrvrName+2, pThis->pDrvrName, (void*) &pThis->Drvr);
- }
- if(pThis->pDrvrName != NULL)
- free(pThis->pDrvrName);
ENDobjDestruct(netstrm)
diff --git a/runtime/netstrm.h b/runtime/netstrm.h
index f4205f80..160bbb0b 100644
--- a/runtime/netstrm.h
+++ b/runtime/netstrm.h
@@ -30,7 +30,6 @@
struct netstrm_s {
BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */
nsd_t *pDrvrData; /**< the driver's data elements (at most other places, this is called pNsd) */
- uchar *pDrvrName; /**< nsd driver name to use, or NULL if system default */
nsd_if_t Drvr; /**< our stream driver */
netstrms_t *pNS; /**< pointer to our netstream subsystem object */
};
@@ -48,11 +47,6 @@ BEGINinterface(netstrm) /* name must also be changed in ENDinterface macro! */
rsRetVal (*Rcv)(netstrm_t *pThis, uchar *pRcvBuf, ssize_t *pLenBuf);
rsRetVal (*Send)(netstrm_t *pThis, uchar *pBuf, ssize_t *pLenBuf);
rsRetVal (*Connect)(netstrm_t *pThis, int family, unsigned char *port, unsigned char *host);
- //rsRetVal (*SelectInit)(nsdsel_t **ppSel, netstrm_t *pThis);
- //rsRetVal (*SelectAdd)(nsdsel_t *pSel, netstrm_t *pThis);
- //rsRetVal (*SelectWait)(nsdsel_t *pSel, int *piNumReady);
- //rsRetVal (*SelectIsReady)(nsdsel_t *pSel, int *piNumReady);
- //rsRetVal (*SelectExit)(nsdsel_t **ppSel);
rsRetVal (*GetRemoteHName)(netstrm_t *pThis, uchar **pszName);
rsRetVal (*GetRemoteIP)(netstrm_t *pThis, uchar **pszIP);
ENDinterface(netstrm)
diff --git a/runtime/nsd.h b/runtime/nsd.h
index 044cc266..1b3702a0 100644
--- a/runtime/nsd.h
+++ b/runtime/nsd.h
@@ -51,7 +51,8 @@ BEGINinterface(nsd) /* name must also be changed in ENDinterface macro! */
rsRetVal (*GetRemoteHName)(nsd_t *pThis, uchar **pszName);
rsRetVal (*GetRemoteIP)(nsd_t *pThis, uchar **pszIP);
rsRetVal (*GetSock)(nsd_t *pThis, int *pSock);
- /* GetSock() returns an error if the driver does not use plain
+ rsRetVal (*SetSock)(nsd_t *pThis, int sock);
+ /* GetSock() and SetSock() return an error if the driver does not use plain
* OS sockets. This interface is primarily meant as an internal aid for
* those drivers that utilize the nsd_ptcp to do some of their work.
*/
diff --git a/runtime/nsd_gtls.c b/runtime/nsd_gtls.c
index d2606799..f3622f36 100644
--- a/runtime/nsd_gtls.c
+++ b/runtime/nsd_gtls.c
@@ -117,6 +117,7 @@ gtlsEndSess(nsd_gtls_t *pThis)
BEGINobjConstruct(nsd_gtls) /* be sure to specify the object type also in END macro! */
iRet = nsd_ptcp.Construct(&pThis->pTcp);
pThis->iMode = 1; /* TODO: must be made configurable */
+ pThis->iMode = 0; /* TODO: must be made configurable */
ENDobjConstruct(nsd_gtls)
@@ -127,11 +128,31 @@ CODESTARTobjDestruct(nsd_gtls)
gtlsEndSess(pThis);
}
+RUNLOG_VAR("%p", pThis->pTcp);
if(pThis->pTcp != NULL)
nsd_ptcp.Destruct(&pThis->pTcp);
ENDobjDestruct(nsd_gtls)
+/* Provide access to the underlying OS socket. This is primarily
+ * useful for other drivers (like nsd_gtls) who utilize ourselfs
+ * for some of their functionality. -- rgerhards, 2008-04-18
+ */
+static rsRetVal
+SetSock(nsd_t *pNsd, int sock)
+{
+ DEFiRet;
+ nsd_gtls_t *pThis = (nsd_gtls_t*) pNsd;
+
+ ISOBJ_TYPE_assert((pThis), nsd_gtls);
+ assert(sock >= 0);
+
+ nsd_ptcp.SetSock(pThis->pTcp, sock);
+
+ RETiRet;
+}
+
+
/* abort a connection. This is meant to be called immediately
* before the Destruct call. -- rgerhards, 2008-03-24
*/
@@ -153,19 +174,73 @@ Abort(nsd_t *pNsd)
/* initialize the tcp socket for a listner
- * pLstnPort must point to a port name or number. NULL is NOT permitted
- * (hint: we need to be careful when we use this module together with librelp,
- * there NULL indicates the default port
- * default is used.
- * gerhards, 2008-03-17
+ * Here, we use the ptcp driver - because there is nothing special
+ * at this point with GnuTLS. Things become special once we accept
+ * a session, but not during listener setup.
+ * gerhards, 2008-04-25
*/
static rsRetVal
LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
uchar *pLstnPort, uchar *pLstnIP, int iSessMax)
{
DEFiRet;
+ iRet = nsd_ptcp.LstnInit(pNS, pUsr, fAddLstn, pLstnPort, pLstnIP, iSessMax);
+ RETiRet;
+}
+
+
+/* get the remote hostname. The returned hostname must be freed by the caller.
+ * rgerhards, 2008-04-25
+ */
+static rsRetVal
+GetRemoteHName(nsd_t *pNsd, uchar **ppszHName)
+{
+ DEFiRet;
+ nsd_gtls_t *pThis = (nsd_gtls_t*) pNsd;
+ ISOBJ_TYPE_assert(pThis, nsd_gtls);
+ iRet = nsd_ptcp.GetRemoteHName(pThis->pTcp, ppszHName);
+ RETiRet;
+}
+
+
+/* get the remote host's IP address. The returned string must be freed by the
+ * caller.
+ * rgerhards, 2008-04-25
+ */
+static rsRetVal
+GetRemoteIP(nsd_t *pNsd, uchar **ppszIP)
+{
+ DEFiRet;
+ nsd_gtls_t *pThis = (nsd_gtls_t*) pNsd;
+ ISOBJ_TYPE_assert(pThis, nsd_gtls);
+ iRet = nsd_ptcp.GetRemoteIP(pThis->pTcp, ppszIP);
+ RETiRet;
+}
+
+
+/* accept an incoming connection request - here, we do the usual accept
+ * handling. TLS specific handling is done thereafter (and if we run in TLS
+ * mode at this time).
+ * rgerhards, 2008-04-25
+ */
+static rsRetVal
+AcceptConnReq(nsd_t *pNsd, nsd_t **ppNew)
+{
+ DEFiRet;
+ nsd_gtls_t *pNew = NULL;
+ nsd_gtls_t *pThis = (nsd_gtls_t*) pNsd;
+
+ ISOBJ_TYPE_assert((pThis), nsd_gtls);
+ CHKiRet(nsd_gtlsConstruct(&pNew));
+ CHKiRet(nsd_ptcp.AcceptConnReq(pThis->pTcp, &pNew->pTcp));
+
+ *ppNew = (nsd_t*) pNew;
finalize_it:
+ if(iRet != RS_RET_OK) {
+ if(pNew != NULL)
+ nsd_gtlsDestruct(&pNew);
+ }
RETiRet;
}
@@ -187,6 +262,7 @@ Rcv(nsd_t *pNsd, uchar *pBuf, ssize_t *pLenBuf)
ISOBJ_TYPE_assert(pThis, nsd_gtls);
if(pThis->iMode == 0) {
+RUNLOG;
CHKiRet(nsd_ptcp.Rcv(pThis->pTcp, pBuf, pLenBuf));
FINALIZE;
}
@@ -302,10 +378,13 @@ CODESTARTobjQueryInterface(nsd_gtls)
pIf->Destruct = (rsRetVal(*)(nsd_t**)) nsd_gtlsDestruct;
pIf->Abort = Abort;
pIf->LstnInit = LstnInit;
- //pIf->AcceptConnReq = AcceptConnReq;
+ pIf->AcceptConnReq = AcceptConnReq;
pIf->Rcv = Rcv;
pIf->Send = Send;
pIf->Connect = Connect;
+ pIf->SetSock = SetSock;
+ pIf->GetRemoteHName = GetRemoteHName;
+ pIf->GetRemoteIP = GetRemoteIP;
finalize_it:
ENDobjQueryInterface(nsd_gtls)
diff --git a/runtime/nsd_ptcp.c b/runtime/nsd_ptcp.c
index 584cc93f..2a74e061 100644
--- a/runtime/nsd_ptcp.c
+++ b/runtime/nsd_ptcp.c
@@ -93,7 +93,6 @@ ENDobjDestruct(nsd_ptcp)
/* Provide access to the underlying OS socket. This is primarily
* useful for other drivers (like nsd_gtls) who utilize ourselfs
* for some of their functionality. -- rgerhards, 2008-04-18
- * TODO: what about the server socket structure?
*/
static rsRetVal
GetSock(nsd_t *pNsd, int *pSock)
@@ -110,6 +109,26 @@ GetSock(nsd_t *pNsd, int *pSock)
}
+/* Provide access to the underlying OS socket. This is primarily
+ * useful for other drivers (like nsd_gtls) who utilize ourselfs
+ * for some of their functionality.
+ * This function sets the socket -- rgerhards, 2008-04-25
+ */
+static rsRetVal
+SetSock(nsd_t *pNsd, int sock)
+{
+ nsd_ptcp_t *pThis = (nsd_ptcp_t*) pNsd;
+ DEFiRet;
+
+ ISOBJ_TYPE_assert((pThis), nsd_ptcp);
+ assert(sock >= 0);
+
+ pThis->sock = sock;
+
+ RETiRet;
+}
+
+
/* abort a connection. This is meant to be called immediately
* before the Destruct call. -- rgerhards, 2008-03-24
*/
@@ -211,7 +230,6 @@ finalize_it:
}
-
/* accept an incoming connection request
* rgerhards, 2008-04-22
*/
@@ -397,10 +415,13 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
* construct a new netstrm obj and hand it over to the upper layers for inclusion
* into their socket array. -- rgerhards, 2008-04-23
*/
+RUNLOG_VAR("%d", sock);
CHKiRet(pNS->Drvr.Construct(&pNewNsd));
- ((nsd_ptcp_t*)pNewNsd)->sock = sock;
+ CHKiRet(pNS->Drvr.SetSock(pNewNsd, sock));
+RUNLOG;
CHKiRet(netstrms.CreateStrm(pNS, &pNewStrm));
pNewStrm->pDrvrData = (nsd_t*) pNewNsd;
+RUNLOG;
CHKiRet(fAddLstn(pUsr, pNewStrm));
pNewNsd = NULL;
pNewStrm = NULL;
@@ -587,6 +608,7 @@ CODESTARTobjQueryInterface(nsd_ptcp)
pIf->Destruct = (rsRetVal(*)(nsd_t**)) nsd_ptcpDestruct;
pIf->Abort = Abort;
pIf->GetSock = GetSock;
+ pIf->SetSock = SetSock;
pIf->Rcv = Rcv;
pIf->Send = Send;
pIf->LstnInit = LstnInit;
diff --git a/runtime/nsdsel_gtls.c b/runtime/nsdsel_gtls.c
index e32dfd10..7cafec49 100644
--- a/runtime/nsdsel_gtls.c
+++ b/runtime/nsdsel_gtls.c
@@ -36,6 +36,7 @@
#include "obj.h"
#include "errmsg.h"
#include "nsd.h"
+#include "nsd_gtls.h"
#include "nsdsel_ptcp.h"
#include "nsdsel_gtls.h"
@@ -68,7 +69,12 @@ static rsRetVal
Add(nsdsel_t *pNsdsel, nsd_t *pNsd, nsdsel_waitOp_t waitOp)
{
DEFiRet;
- iRet = nsdsel_ptcp.Add(pNsdsel, pNsd, waitOp);
+ nsdsel_gtls_t *pThis = (nsdsel_gtls_t*) pNsdsel;
+ nsd_gtls_t *pNsdGTLS = (nsd_gtls_t*) pNsd;
+
+ ISOBJ_TYPE_assert(pThis, nsdsel_gtls);
+ ISOBJ_TYPE_assert(pNsdGTLS, nsd_gtls);
+ iRet = nsdsel_ptcp.Add(pThis->pTcp, pNsdGTLS->pTcp, waitOp);
RETiRet;
}
@@ -80,7 +86,10 @@ static rsRetVal
Select(nsdsel_t *pNsdsel, int *piNumReady)
{
DEFiRet;
- iRet = nsdsel_ptcp.Select(pNsdsel, piNumReady);
+ nsdsel_gtls_t *pThis = (nsdsel_gtls_t*) pNsdsel;
+
+ ISOBJ_TYPE_assert(pThis, nsdsel_gtls);
+ iRet = nsdsel_ptcp.Select(pThis->pTcp, piNumReady);
RETiRet;
}
@@ -90,7 +99,12 @@ static rsRetVal
IsReady(nsdsel_t *pNsdsel, nsd_t *pNsd, nsdsel_waitOp_t waitOp, int *pbIsReady)
{
DEFiRet;
- iRet = nsdsel_ptcp.IsReady(pNsdsel, pNsd, waitOp, pbIsReady);
+ nsdsel_gtls_t *pThis = (nsdsel_gtls_t*) pNsdsel;
+ nsd_gtls_t *pNsdGTLS = (nsd_gtls_t*) pNsd;
+
+ ISOBJ_TYPE_assert(pThis, nsdsel_gtls);
+ ISOBJ_TYPE_assert(pNsdGTLS, nsd_gtls);
+ iRet = nsdsel_ptcp.IsReady(pThis->pTcp, pNsdGTLS->pTcp, waitOp, pbIsReady);
RETiRet;
}
diff --git a/runtime/nsdsel_ptcp.c b/runtime/nsdsel_ptcp.c
index b439063a..22c000b9 100644
--- a/runtime/nsdsel_ptcp.c
+++ b/runtime/nsdsel_ptcp.c
@@ -71,6 +71,8 @@ Add(nsdsel_t *pNsdsel, nsd_t *pNsd, nsdsel_waitOp_t waitOp)
ISOBJ_TYPE_assert(pSock, nsd_ptcp);
ISOBJ_TYPE_assert(pThis, nsdsel_ptcp);
+RUNLOG_VAR("%d", pSock->sock);
+RUNLOG_VAR("%p", &pThis->readfds);
switch(waitOp) {
case NSDSEL_RD:
FD_SET(pSock->sock, &pThis->readfds);
diff --git a/runtime/nssel.c b/runtime/nssel.c
index 7cb63e98..5333fc75 100644
--- a/runtime/nssel.c
+++ b/runtime/nssel.c
@@ -75,7 +75,7 @@ loadDrvr(nssel_t *pThis)
* enough. -- rgerhards, 2008-04-18
*/
//CHKiRet(obj.UseObj(__FILE__, pDrvrName+2, pDrvrName, (void*) &pThis->Drvr));
- CHKiRet(obj.UseObj(__FILE__, "nsdsel_ptcp", "lmnsdsel_ptcp", (void*) &pThis->Drvr));
+ CHKiRet(obj.UseObj(__FILE__, "nsdsel_gtls", "lmnsdsel_gtls", (void*) &pThis->Drvr));
finalize_it:
RETiRet;
}
diff --git a/runtime/obj-types.h b/runtime/obj-types.h
index 2d0e0f14..5f531eb1 100644
--- a/runtime/obj-types.h
+++ b/runtime/obj-types.h
@@ -107,8 +107,8 @@ struct obj_s { /* the dummy struct that each derived class can be casted to */
ASSERT(pObj != NULL); \
ASSERT((unsigned) ((obj_t*) (pObj))->iObjCooCKiE == (unsigned) 0xBADEFEE); \
if(strcmp((char*)(((obj_t*)pObj)->pObjInfo->pszID), #objType)) { \
- dbgprintf("ISOBJ assert failure: invalid object type, expected '%s' " \
- "actual '%s'\n", #objType, (((obj_t*)pObj)->pObjInfo->pszID)); \
+ dbgprintf("%s:%d ISOBJ assert failure: invalid object type, expected '%s' " \
+ "actual '%s'\n", __FILE__, __LINE__, #objType, (((obj_t*)pObj)->pObjInfo->pszID)); \
assert(0); /* trigger assertion, messge we already have */ \
} \
} while(0)
diff --git a/tcpsrv.c b/tcpsrv.c
index 086d17b8..638d7019 100644
--- a/tcpsrv.c
+++ b/tcpsrv.c
@@ -242,7 +242,6 @@ addTcpLstn(void *pUsr, netstrm_t *pLstn)
if(pThis->iLstnMax >= TCPLSTN_MAX_DEFAULT)
ABORT_FINALIZE(RS_RET_MAX_LSTN_REACHED);
-RUNLOG_VAR("%d", pThis->iLstnMax);
pThis->ppLstn[pThis->iLstnMax] = pLstn;
++pThis->iLstnMax;
@@ -416,6 +415,7 @@ Run(tcpsrv_t *pThis)
/* Add the TCP listen sockets to the list of read descriptors. */
for(i = 0 ; i < pThis->iLstnMax ; ++i) {
+RUNLOG_VAR("%d", i);
CHKiRet(nssel.Add(pSel, pThis->ppLstn[i], NSDSEL_RD));
}