botsense  3.2.0
RoadNarrows Client-Server Proxied Services Framework
bsLibError.c
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: BotSense
4 //
5 // Library: libbotsense
6 //
7 // File: bsLibError.c
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2010-09-25 09:06:47 -0600 (Sat, 25 Sep 2010) $
12  * $Rev: 605 $
13  *
14  * \brief Error and logging handling routines.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \copyright
19  * \h_copy 2009-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 // Permission is hereby granted, without written agreement and without
24 // license or royalty fees, to use, copy, modify, and distribute this
25 // software and its documentation for any purpose, provided that
26 // (1) The above copyright notice and the following two paragraphs
27 // appear in all copies of the source code and (2) redistributions
28 // including binaries reproduces these notices in the supporting
29 // documentation. Substantial modifications to this software may be
30 // copyrighted by their authors and need not follow the licensing terms
31 // described here, provided that the new terms are clearly indicated in
32 // all files where they apply.
33 //
34 // IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
35 // OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
36 // PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
37 // DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
38 // EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
39 // THE POSSIBILITY OF SUCH DAMAGE.
40 //
41 // THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
42 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
43 // FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
44 // "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
45 // PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
46 //
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <libgen.h>
52 #include <string.h>
53 
54 #include "rnr/rnrconfig.h"
55 #include "rnr/log.h"
56 
57 #include "botsense/BotSense.h"
58 #include "botsense/libBotSense.h"
59 
60 #include "bsLibInternal.h"
61 
62 
63 // ---------------------------------------------------------------------------
64 // Private Interface
65 // ---------------------------------------------------------------------------
66 
67 /*!
68  * \brief \h_botsense Error Code String Table.
69  *
70  * Table is indexed by \h_botsense error codes (see \ref bs_ecodes). Keep
71  * in sync.
72  */
73 static const char *bsEcodeStrTbl[] =
74 {
75  "Ok", ///< [BS_OK]
76 
77  "Error", ///< [BS_ECODE_GEN]
78  "Receive error", ///< [BS_ECODE_BAD_RECV]
79  "Send error", ///< [BS_ECODE_BAD_SEND]
80  "Failed to resynchronize", ///< [BS_ECODE_BAD_RESYNC]
81  "Bad message header", ///< [BS_ECODE_MSG_BAD_HDR]
82  "Message fragment", ///< [BS_ECODE_MSG_FRAG]
83  "Message too big", ///< [BS_ECODE_MSG_TOO_BIG]
84  "Buffer too small", ///< [BS_ECODE_BUF_TOO_SMALL]
85  "Message corrupted", ///< [BS_ECODE_BAD_MSG]
86  "Invalid value", ///< [BS_ECODE_BAD_VAL]
87  "Bad or unknown transaction id", ///< [BS_ECODE_MSG_BAD_TID]
88  "Bad virtual connection handle", ///< [BS_ECODE_BAD_VCONN_HND]
89  "Virtual connection not found", ///< [BS_ECODE_NO_VCONN]
90  "Unknown request", ///< [BS_ECODE_UNKNOWN_REQ]
91  "No proxied device", ///< [BS_ECODE_NO_DEV]
92  "No interface module", ///< [BS_ECODE_NO_MOD]
93  "Bad interface module", ///< [BS_ECODE_BAD_MOD]
94  "No resources available", ///< [BS_ECODE_NO_RSRC]
95  "Resource busy", ///< [BS_ECODE_BUSY]
96  "Operation timed out", ///< [BS_ECODE_TIMEDOUT]
97  "Cannot execute", ///< [BS_ECODE_NO_EXEC]
98  "Connection failed", ///< [BS_ECODE_SERVER_CONN_FAIL]
99  "Connection denied", ///< [BS_ECODE_SERVER_CONN_DENY]
100  "Bad or unknown client", ///< [BS_ECODE_SERVER_BAD_CLIENT]
101  "System error", ///< [BS_ECODE_SYS]
102  "Internal error", ///< [BS_ECODE_INTERNAL]
103  "Invalid error code" ///< [BS_ECODE_BADEC]
104 };
105 
106 
107 // ---------------------------------------------------------------------------
108 // Public Interface
109 // ---------------------------------------------------------------------------
110 
111 /*!
112  * \brief Get the error string describing the \h_botsense error code.
113  *
114  * The absolute value of the error code is taken prior retrieving the string.
115  * An unknown or out-of-range error code will be mapped to
116  * \ref BS_ECODE_BADEC.
117  *
118  * \param ecode \h_botsense error code.
119  *
120  * \return Returns the appropriate error code string.
121  */
122 const char *bsStrError(int ecode)
123 {
124  if( ecode < 0 )
125  {
126  ecode = -ecode;
127  }
128 
129  if( ecode >= arraysize(bsEcodeStrTbl) )
130  {
131  ecode = BS_ECODE_BADEC;
132  }
133  return bsEcodeStrTbl[ecode];
134 }
The libBotSense internal declarations.
#define BS_ECODE_BADEC
bad error code
Definition: BotSense.h:95
<b><i>BotSense</i></b> client library declarations.
const char * bsStrError(int ecode)
Get the error string describing the <b><i>BotSense</i></b> error code.
Definition: bsLibError.c:122
static const char * bsEcodeStrTbl[]
<b><i>BotSense</i></b> Error Code String Table.
Definition: bsLibError.c:73
<b><i>BotSense</i></b> package top-level, unifying header declarations.