Main Page | Compound List | File List | Compound Members | File Members | Related Pages

# beepsession.h File Reference

The BEEP Session Object. More...

`#include "beepchannel.h"`
`#include "beepprofile.h"`

Go to the source code of this file.

## Compounds
struct | sbSessObject
| The session object. More...
## Defines
#define | __LIB3195_BEEPSESSION_H_INCLUDED__ 1
#define | sbSessCHECKVALIDOBJECT(x) {assert((x) != NULL); assert((x)->OID == OIDsbSess);}
#define | sbSessGetLastError(pThis) pThis->iLastErr
| Getthe last error for this module.
#define | sbSessSetLastError(pThis, iRet) pThis->iLastErr = iRet
| Set the last error for this module.
#define | sbSessResetLastError(pThis) pThis->iLastErr = SR_RET_OK
| reset the last error for this module
## Typedefs
typedef enum sbSessState_ | sbSessState
typedef enum sbSessTXState_ | sbSessTXState
typedef sbSessObject | sbSessObj
## Enumerations
enum | sbSessState_ { sbSESSSTATE_OPEN, sbSESSSTATE_CLOSED, sbSESSSTATE_UNKNOWN = 0 }
| Session status. More...
enum | sbSessTXState_ { sbSESSTXSTATE_NO_TX_PENDING, sbSESSTXSTATE_IN_TX, sbSESSTXSTATE_UNKNOWN = 0 }
## Functions
sbSessObj * | sbSessOpenSession (char *pszRemotePeer, int iPort, struct sbNVTRObject *pProfSupported)
| Open a BEEP session.
srRetVal | sbSessCloseSession (sbSessObj *pThis)
| Closes the BEEP session.
sbChanObject * | sbSessRetrChanObj (sbSessObj *pThis, SBchannel uChanNo)
| Retrieve the channel object associated with the channel number.
sbFramObject * | sbSessRecvFram (sbSessObj *pThis, struct sbChanObject *pChan)
| Receive a frame for a specified channel from the tcp stream.
sbChanObject * | sbSessOpenChan (sbSessObj *pThis)
| Open a BEEP channel on an established session.
srRetVal | sbSessCloseChan (sbSessObj *pThis, struct sbChanObject *pChan)
| Close a channel.
srRetVal | sbSessDoReceive (sbSessObj *pThis, int bMustRcvPayloadFrame)
| Receive frames off the tcp stream.
srRetVal | sbSessSendFram (sbSessObj *pThis, struct sbFramObject *pFram, struct sbChanObject *pChan)
| Send the provided frame on the provided channel.
void | sbSessDestroy (sbSessObj *pThis)
| Destructor.
srRetVal | sbSessRemoteOpen (sbSessObj **pThis, sbSockObj *pSock, struct sbNVTRObject *pProfSupported)
| Open a BEEP session.
void | sbSessAbort (sbSessObj *pThis)
| Close a session without any further communication.
srRetVal | sbSessProcessGreeting (struct sbSessObject *pThis, struct sbMesgObject *pMesg)
| Process the remote peer's greeting message.
srRetVal | sbSessSendGreeting (struct sbSessObject *pSess, struct sbNVTRObject *pProfsSupported)
| Send a greeting message based on the currently registered profiles.

## Detailed Description

The BEEP Session Object.

Note:
  The current implementation only supports 2 channels - the control channel plus 1 payload channel.

Author:
  Rainer Gerhards <rgerhards@adiscon.com>

Date:
  2003-08-04 0.1 version created.

  2003-08-07 name value list for channnels added.

Copyright 2002-2003 Rainer Gerhards and Adiscon GmbH. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Neither the name of Adiscon GmbH or Rainer Gerhards nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

## Enumeration Type Documentation

enum sbSessState_

  | Session status. Enumeration values:
  sbSESSSTATE_CLOSED | session is closed and ready to be removed from whatever queues it is in
  sbSESSSTATE_UNKNOWN | should never happen Set after initialization.

enum sbSessTXState_

  | Enumeration values:
  sbSESSTXSTATE_NO_TX_PENDING | no transmit pending
  sbSESSTXSTATE_IN_TX | data is currently being send
  sbSESSTXSTATE_UNKNOWN | should never happen Set after initialization.

## Function Documentation

void sbSessAbort | ( | sbSessObj * | pThis | ) |

| Close a session without any further communication. Can be used to abort a connection if the remote peer broke it we have a protocol error and we need to break it This method is void, because it *must* complete, no matter which errors it encounters. Furthermore, it is primarily intended to be called from destructors which are also void. Consider it to be an extended desctrutor.

srRetVal sbSessCloseChan | ( | sbSessObj * | pThis,
|  | struct sbChanObject * | pChan
| ) |

  | Close a channel. This is a very partial implementation of RFC 3080. For syslog-raw, I honestly and strongly beliefe it works. However, there may be implementations of syslog raw where it will not work or at least not work fully correctly. Todo: This method (and some of the plumbing behind) must be updated to be fully compliant to RFC 3080. Issues are: we do not expect other messages to come in during the session if the remote peer closes the session before us, we may be in trouble Parameters:
  pChan | [in] Channel to be closed. Will be destroyed at the end of the execution and thus can no longer be used after this method call!

srRetVal sbSessCloseSession | ( | sbSessObj * | pThis | ) |

| Closes the BEEP session. First, the management channel (channel 0) is taken down and then the TCP stream is closed. This function can only be called after all sessions have been closed. Once the function returns, the session object is no longer valid and can no longer be used.

void sbSessDestroy | ( | sbSessObj * | pThis | ) |

| Destructor. pThis is invalid when this function returns. The caller can no longer use it. The caller is also not allowed to free it - this is already done in this method.

srRetVal sbSessDoReceive | ( | sbSessObj * | pThis,
|  | int | bMustRcvPayloadFrame
| ) |

  | Receive frames off the tcp stream. SEQ frames are processed as they arrive. Other frames are buffered in the respective in-memory queue. This is a helper to sbSessRecvFram() and sbSessSendFram(). Parameters:
  bMustRcvPayloadFrame | A boolean indicating if an actual payload frame must be received. If set to TRUE, the method blocks until a payload frame is received. All interim SEQ frames are processed, but will not make this method to return. If FALSE, the method will block until anything is received, including a SEQ. If a SEQ is received, it will be processed and the method returns.

struct sbChanObject* sbSessOpenChan | ( | sbSessObj * | pThis | ) |

| Open a BEEP channel on an established session. Todo: think if we need to shut down anything else inside the BEEP session. think if we need to shut down anything else inside the BEEP session.

sbSessObj* sbSessOpenSession | ( | char * | pszRemotePeer,
|  | int | iPort,
|  | struct sbNVTRObject * | pProfSupported
| ) |

  | Open a BEEP session. The initial greeting is sent and the remote peers initial greeting is accepted. Channel 0 is initialized and brought into operation. Parameters:
  pszRemotePeer | name or IP address of the peer to connect to
  iPort | TCP port the remote peer is listening to
  Return values:
  pointer | to the new session object or NULL, if an error occured.

srRetVal sbSessProcessGreeting | ( | struct sbSessObject * | pThis,
|  | struct sbMesgObject * | pMesg
| ) |

  | Process the remote peer's greeting message. Most importantly, the list of profiles is extracted and stored in the session object. Parameters:
  pMesg | The message containing the Greeting. Must not be NULL.

struct sbFramObject* sbSessRecvFram | ( | sbSessObj * | pThis,
|  | struct sbChanObject * | pChan
| ) |

  | Receive a frame for a specified channel from the tcp stream. This method handles intermixed frames from other channels. It calls back into the frame object to do the actual frame read (if no frame is buffered). See architecture::c for a full description. Parameters:
  pChan | the associated channel
  Return values:
  pointer | to the new frame object or NULL, if an error occured.

srRetVal sbSessRemoteOpen | ( | sbSessObj ** | pThis,
|  | sbSockObj * | pSock,
|  | struct sbNVTRObject * | pProfSupported
| ) |

| Open a BEEP session. This method is called if a REMOTE peer requests an session open. As such, it does only the most pressing initialization work and then returns back to the caller.

struct sbChanObject* sbSessRetrChanObj | ( | sbSessObj * | pThis,
|  | SBchannel | uChanNo
| ) |

  | Retrieve the channel object associated with the channel number. This method allows to retrieve a channel number based on the actual channel. Parameters:
  uChanNo | channel number
  Return values:
  pointer | to channel object or NULL, if uChanNo could not be found.

srRetVal sbSessSendFram | ( | sbSessObj * | pThis,
|  | struct sbFramObject * | pFram,
|  | struct sbChanObject * | pChan
| ) |

  | Send the provided frame on the provided channel. While sending, concurrently incoming frames are buffered and SEQ frames are processed. This method blocks until pFram could be sent (this means it may need to wait for the proper SEQ frame). See architecture::c for full details on how this method "drives the BEEP stack". Parameters:
  pFram | [in] frame to be send
  pChan | [in] channel where pFram is to be sent over

srRetVal sbSessSendGreeting | ( | struct sbSessObject * | pSess,
|  | struct sbNVTRObject * | pProfsSupported
| ) |

  | Send a greeting message based on the currently registered profiles. We generate the greeting via a simple stringbuf, not with an XML parser. This saves execution time and is as good as the XML thing... Parameters:
  pProfsSupported | Pointer to a linked list of supported profiles (which should be specified in the greeting.