/* This accepts a new session, and, if all goes well, constructs a new * session object and adds it to the engine's list of sessions. * rgerhards, 2008-03-17 */ relpRetVal relpSessAcceptAndConstruct(relpSess_t **ppThis, relpSrv_t *pSrv, int sock) { relpSess_t *pThis; ENTER_RELPFUNC; assert(ppThis != NULL); RELPOBJ_assert(pSrv, Srv); assert(sock >= 0); CHKRet(relpSessConstruct(&pThis, pSrv->pEngine, pSrv)); CHKRet(relpTcpAcceptConnReq(&pThis->pTcp, sock, pThis->pEngine)); /* TODO: check hostname against ACL (callback?) */ /* TODO: check against max# sessions */ *ppThis = pThis; finalize_it: pSrv->pEngine->dbgprint("relp session accepted with state %d\n", iRet); if(iRet != RELP_RET_OK) { if(pThis != NULL) relpSessDestruct(&pThis); } LEAVE_RELPFUNC; }
/** Construct a RELP sess instance * the pSrv parameter may be set to NULL if the session object is for a client. */ relpRetVal relpSessConstruct(relpSess_t **ppThis, relpEngine_t *pEngine, int connType, void *pParent) { relpSess_t *pThis; ENTER_RELPFUNC; assert(ppThis != NULL); RELPOBJ_assert(pEngine, Engine); if((pThis = calloc(1, sizeof(relpSess_t))) == NULL) { ABORT_FINALIZE(RELP_RET_OUT_OF_MEMORY); } RELP_CORE_CONSTRUCTOR(pThis, Sess); pThis->pEngine = pEngine; /* use Engine's command enablement states as default */ pThis->stateCmdSyslog = pEngine->stateCmdSyslog; if(connType == RELP_SRV_CONN) { pThis->pSrv = (relpSrv_t*) pParent; } else { pThis->pClt = (relpClt_t*) pParent; } pThis->txnr = 1; /* txnr start at 1 according to spec */ pThis->timeout = 90; pThis->pUsr = NULL; pThis->sizeWindow = RELP_DFLT_WINDOW_SIZE; pThis->maxDataSize = RELP_DFLT_MAX_DATA_SIZE; pThis->authmode = eRelpAuthMode_None; pThis->pristring = NULL; pThis->caCertFile = NULL; pThis->ownCertFile = NULL; pThis->privKeyFile = NULL; pThis->permittedPeers.nmemb = 0; CHKRet(relpSendqConstruct(&pThis->pSendq, pThis->pEngine)); pthread_mutex_init(&pThis->mutSend, NULL); *ppThis = pThis; finalize_it: if(iRet != RELP_RET_OK) { if(pThis != NULL) { relpSessDestruct(&pThis); } } LEAVE_RELPFUNC; }
/** open a relp session to a remote peer * remote servers parameters must already have been set. * rgerhards, 2008-03-19 */ relpRetVal relpCltConnect(relpClt_t *pThis, int protFamily, unsigned char *port, unsigned char *host) { ENTER_RELPFUNC; RELPOBJ_assert(pThis, Clt); CHKRet(relpSessConstruct(&pThis->pSess, pThis->pEngine, NULL)); CHKRet(relpSessConnect(pThis->pSess, protFamily, port, host)); finalize_it: if(iRet != RELP_RET_OK) { if(pThis->pSess != NULL) { relpSessDestruct(&pThis->pSess); } } LEAVE_RELPFUNC; }
/** Destruct a RELP clt instance */ relpRetVal relpCltDestruct(relpClt_t **ppThis) { relpClt_t *pThis; ENTER_RELPFUNC; assert(ppThis != NULL); pThis = *ppThis; RELPOBJ_assert(pThis, Clt); if(pThis->pSess != NULL) relpSessDestruct(&pThis->pSess); /* done with de-init work, now free clt object itself */ free(pThis); *ppThis = NULL; LEAVE_RELPFUNC; }
/* This accepts a new session, and, if all goes well, constructs a new * session object and adds it to the engine's list of sessions. * rgerhards, 2008-03-17 */ relpRetVal relpSessAcceptAndConstruct(relpSess_t **ppThis, relpSrv_t *pSrv, int sock) { relpSess_t *pThis; ENTER_RELPFUNC; assert(ppThis != NULL); RELPOBJ_assert(pSrv, Srv); assert(sock >= 0); CHKRet(relpSessConstruct(&pThis, pSrv->pEngine, RELP_SRV_CONN, pSrv)); CHKRet(relpTcpAcceptConnReq(&pThis->pTcp, sock, pSrv)); *ppThis = pThis; finalize_it: if(iRet != RELP_RET_OK) { if(pThis != NULL) relpSessDestruct(&pThis); } LEAVE_RELPFUNC; }
/** Construct a RELP sess instance * the pSrv parameter may be set to NULL if the session object is for a client. */ relpRetVal relpSessConstruct(relpSess_t **ppThis, relpEngine_t *pEngine, relpSrv_t *pSrv) { relpSess_t *pThis; ENTER_RELPFUNC; assert(ppThis != NULL); RELPOBJ_assert(pEngine, Engine); if((pThis = calloc(1, sizeof(relpSess_t))) == NULL) { ABORT_FINALIZE(RELP_RET_OUT_OF_MEMORY); } RELP_CORE_CONSTRUCTOR(pThis, Sess); pThis->pEngine = pEngine; /* use Engine's command enablement states as default */ pThis->stateCmdSyslog = pEngine->stateCmdSyslog; pThis->pSrv = pSrv; pThis->txnr = 1; /* txnr start at 1 according to spec */ pThis->timeout = 10; /* TODO: make configurable */ pThis->sizeWindow = RELP_DFLT_WINDOW_SIZE; /* TODO: make configurable */ pThis->maxDataSize = RELP_DFLT_MAX_DATA_SIZE; CHKRet(relpSendqConstruct(&pThis->pSendq, pThis->pEngine)); pthread_mutex_init(&pThis->mutSend, NULL); *ppThis = pThis; finalize_it: if(iRet != RELP_RET_OK) { if(pThis != NULL) { relpSessDestruct(&pThis); } } LEAVE_RELPFUNC; }