1 /******************************************************************************
2  * $Id$
3  *
4  * Project:  MapServer
5  * Purpose:  Declarations for Error and Debug functions.
6  * Author:   Steve Lime and the MapServer team.
7  *
8  ******************************************************************************
9  * Copyright (c) 1996-2005 Regents of the University of Minnesota.
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies of this Software or works derived from this Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ****************************************************************************/
29 
30 #ifndef MAPERROR_H
31 #define MAPERROR_H
32 
33 #include "mapthread.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39   /*====================================================================
40    *   maperror.c
41    *====================================================================*/
42 
43 #define MS_NOERR 0 /* general error codes */
44 #define MS_IOERR 1
45 #define MS_MEMERR 2
46 #define MS_TYPEERR 3
47 #define MS_SYMERR 4
48 #define MS_REGEXERR 5
49 #define MS_TTFERR 6
50 #define MS_DBFERR 7
51 #define MS_IDENTERR 9
52 #define MS_EOFERR 10
53 #define MS_PROJERR 11
54 #define MS_MISCERR 12
55 #define MS_CGIERR 13
56 #define MS_WEBERR 14
57 #define MS_IMGERR 15
58 #define MS_HASHERR 16
59 #define MS_JOINERR 17
60 #define MS_NOTFOUND 18 /* empty search results */
61 #define MS_SHPERR 19
62 #define MS_PARSEERR 20
63 #define MS_UNUSEDERR 21
64 #define MS_OGRERR 22
65 #define MS_QUERYERR 23
66 #define MS_WMSERR 24      /* WMS server error */
67 #define MS_WMSCONNERR 25  /* WMS connectiontype error */
68 #define MS_ORACLESPATIALERR 26
69 #define MS_WFSERR 27      /* WFS server error */
70 #define MS_WFSCONNERR 28  /* WFS connectiontype error */
71 #define MS_MAPCONTEXTERR 29 /* Map Context error */
72 #define MS_HTTPERR 30
73 #define MS_CHILDERR 31    /* Errors involving arrays of child objects */
74 #define MS_WCSERR 32
75 #define MS_GEOSERR 33
76 #define MS_RECTERR 34
77 #define MS_TIMEERR 35
78 #define MS_GMLERR 36
79 #define MS_SOSERR 37
80 #define MS_NULLPARENTERR 38
81 #define MS_AGGERR 39
82 #define MS_OWSERR 40
83 #define MS_OGLERR 41
84 #define MS_RENDERERERR 42
85 #define MS_V8ERR 43
86 #define MS_NUMERRORCODES 44
87 
88 #define MESSAGELENGTH 2048
89 #define ROUTINELENGTH 64
90 
91 #define MS_ERROR_LANGUAGE "en-US"
92 
93 #if defined(_WIN32) && !defined(__CYGWIN__)
94 #  define MS_DLL_EXPORT     __declspec(dllexport)
95 #else
96 #define  MS_DLL_EXPORT
97 #endif
98 
99 #ifndef MS_PRINT_FUNC_FORMAT
100 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
101 #define MS_PRINT_FUNC_FORMAT( format_idx, arg_idx )  __attribute__((__format__ (__printf__, format_idx, arg_idx)))
102 #else
103 #define MS_PRINT_FUNC_FORMAT( format_idx, arg_idx )
104 #endif
105 #endif
106 
107   typedef struct errorObj {
108     int code;
109     char routine[ROUTINELENGTH];
110     char message[MESSAGELENGTH];
111     int isreported;
112     int errorcount; /* number of subsequent errors */
113 #ifndef SWIG
114     struct errorObj *next;
115 #endif
116   } errorObj;
117 
118   /*
119   ** Function prototypes
120   */
121   MS_DLL_EXPORT errorObj *msGetErrorObj(void);
122   MS_DLL_EXPORT void msResetErrorList(void);
123   MS_DLL_EXPORT char *msGetVersion(void);
124   MS_DLL_EXPORT int  msGetVersionInt(void);
125   MS_DLL_EXPORT char *msGetErrorString(char *delimiter);
126 
127 #ifndef SWIG
128   MS_DLL_EXPORT void msSetError(int code, const char *message, const char *routine, ...) MS_PRINT_FUNC_FORMAT(2,4) ;
129   MS_DLL_EXPORT void msWriteError(FILE *stream);
130   MS_DLL_EXPORT void msWriteErrorXML(FILE *stream);
131   MS_DLL_EXPORT char *msGetErrorCodeString(int code);
132   MS_DLL_EXPORT char *msAddErrorDisplayString(char *source, errorObj *error);
133 
134   struct mapObj;
135   MS_DLL_EXPORT void msWriteErrorImage(struct mapObj *map, char *filename, int blank);
136 
137 #endif /* SWIG */
138 
139   /*====================================================================
140    *   mapdebug.c (See also MS-RFC-28)
141    *====================================================================*/
142 
143   typedef enum { MS_DEBUGLEVEL_ERRORSONLY = 0,  /* DEBUG OFF, log fatal errors */
144                  MS_DEBUGLEVEL_DEBUG      = 1,  /* DEBUG ON */
145                  MS_DEBUGLEVEL_TUNING     = 2,  /* Reports timing info */
146                  MS_DEBUGLEVEL_V          = 3,  /* Verbose */
147                  MS_DEBUGLEVEL_VV         = 4,  /* Very verbose */
148                  MS_DEBUGLEVEL_VVV        = 5,  /* Very very verbose */
149                  MS_DEBUGLEVEL_DEVDEBUG   = 20, /* Undocumented, will trigger debug messages only useful for developers */
150                } debugLevel;
151 
152 #ifndef SWIG
153 
154   typedef enum { MS_DEBUGMODE_OFF,
155                  MS_DEBUGMODE_FILE,
156                  MS_DEBUGMODE_STDERR,
157                  MS_DEBUGMODE_STDOUT,
158                  MS_DEBUGMODE_WINDOWSDEBUG
159                } debugMode;
160 
161   typedef struct debug_info_obj {
162     debugLevel  global_debug_level;
163     debugMode   debug_mode;
164     char        *errorfile;
165     FILE        *fp;
166     /* The following 2 members are used only with USE_THREAD (but we won't #ifndef them) */
167     void* thread_id;
168     struct debug_info_obj *next;
169   } debugInfoObj;
170 
171 
172   MS_DLL_EXPORT void msDebug( const char * pszFormat, ... ) MS_PRINT_FUNC_FORMAT(1,2) ;
173   MS_DLL_EXPORT int msSetErrorFile(const char *pszErrorFile, const char *pszRelToPath);
174   MS_DLL_EXPORT void msCloseErrorFile( void );
175   MS_DLL_EXPORT const char *msGetErrorFile( void );
176   MS_DLL_EXPORT void msSetGlobalDebugLevel(int level);
177   MS_DLL_EXPORT debugLevel msGetGlobalDebugLevel( void );
178   MS_DLL_EXPORT int msDebugInitFromEnv( void );
179   MS_DLL_EXPORT void msDebugCleanup( void );
180 
181 #endif /* SWIG */
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 
187 #endif /* MAPERROR_H */
188