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

srAPI.c File Reference

Implementation of the API. More...

#include <assert.h>
#include "config.h"
#include "liblogging.h"
#include "beepsession.h"
#include "beepprofile.h"
#include "beeplisten.h"
#include "namevaluetree.h"
#include "clntprof-3195raw.h"
#include "clntprof-3195cooked.h"
#include "srAPI.h"
#include "syslogmessage.h"

Functions

srAPIObjsrAPIInitLib (void)
 Initialize the liblogging library.

srRetVal srAPISetOption (srAPIObj *pThis, SRoption iOpt, int iOptVal)
 Set an library option.

srRetVal srAPISetStringOption (srAPIObj *pThis, SRoption iOpt, char *pszOptVal)
srRetVal srAPIExitLib (srAPIObj *pThis)
 Exit the liblogging library.

srRetVal srAPIOpenlog (srAPIObj *pThis, char *pszRemotePeer, int iPort)
 Open a log session.

srRetVal srAPISendLogmsg (srAPIObj *pThis, char *szLogmsg)
 Send a log message to the remote peer.

srRetVal srAPISendSLMG (srAPIObj *pThis, srSLMGObj *pSLMG)
srRetVal srAPICloseLog (srAPIObj *pThis)
 Close a syslog raw session.

srRetVal srAPISetUsrPointer (srAPIObj *pAPI, void *pUsr)
 Set the user pointer.

srRetVal srAPIGetUsrPointer (srAPIObj *pAPI, void **ppToStore)
 Return the user pointer.


Detailed Description

Implementation of the API.

Author:
Rainer Gerhards <rgerhards@adiscon.com>
Date:
2003-08-04 Initial version (0.1) released.

2003-09-04 begin major redesign so that multiple client profiles can be supported (the initial design just allowed one).

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.


Function Documentation

srRetVal srAPICloseLog srAPIObj pThis  ) 
 

Close a syslog raw session.

In the method, we have a slightly different error handling. We do NOT return immediately when something goes wrong but rather preserve the error state and try to continue processing. The reasoning behind this is that we can potentially create an even larger memory leak if we do not try to continue. After all, we are here to free things and shutdown the process. The only exception is when we detect that the caller-provided handle is invalid. In this case, we CAN NOT continue processing.

When this method returns, the the caller-supplied pointer to the API object is NO LONGER VALID and can not be used for consequtive calls.

srRetVal srAPIExitLib srAPIObj pThis  ) 
 

Exit the liblogging library.

This method should be called after a higher layer is COMPLETE DONE with liblogging. It does not need to be called after each session close.

if srAPIExitLib() is called, the lib can not be used until srAPIInitLib() is called again.

The provided pointer to the API object is invalid once this method returns.

srRetVal srAPIGetUsrPointer srAPIObj pAPI,
void **  ppToStore
 

Return the user pointer.

Returns whatever is stored in pUsr.

Parameters:
ppToStore Pointer to a pointer that will receive the user pointer.

srAPIObj* srAPIInitLib void   ) 
 

Initialize the liblogging library.

This method must be called before any other method.

Return values:
Pointer to an API object (aka "handle") or NULL if an error occured.

srRetVal srAPIOpenlog srAPIObj pThis,
char *  pszRemotePeer,
int  iPort
 

Open a log session.

This API is effectively the initiator side of the RAW profile.

This method looks like much code, but most of it is error handling ;) - so we keep it as a single long method.

Parameters:
pszRemotePeer [in] The Peer to connect to.
iPort [in] The port the remote Peer is listening to.
Todo:
later, make this depending on the lib option set by the user.

srRetVal srAPISendLogmsg srAPIObj pThis,
char *  szLogmsg
 

Send a log message to the remote peer.

The log message must already be correctly formatted according to RFC 3195. No further formatting (or checks) are applied.

Parameters:
pThis [in] pointer to a proper srAPI object.
szLogmsg [in] message to be sent.

srRetVal srAPISetOption srAPIObj pThis,
SRoption  iOpt,
int  iOptVal
 

Set an library option.

Library options provide a way to modify library behaviour. For example, once rfc3195 raw and cooked are implemented, you can set an option to set which transport you would like to have. Consequently, it currently looks like the calling sequence is probably always:

1. srAPIInitLib 2. srAPISetOption 3. srAPIOpenlog 4. srAPISendLogmsg 5. srAPICloselog 6. srAPIExitLib

Parameters:
pThis pointer to the API, as usual. The unusual things is that in this case it may be NULL. If so, global settings will be modified on a per-library basis.
iOpt option to set
iOptVal value that the option is to be set to. The option value is totally dependent on the respective option.

srRetVal srAPISetUsrPointer srAPIObj pAPI,
void *  pUsr
 

Set the user pointer.

Whatever value the user passes in is accepted and stored. No validation is done (and can be done). Any previously stored information is overwritten.


Generated on Mon Oct 3 12:29:56 2005 for liblogging by doxygen 1.3.2