2012-09-20 07:51:34 +04:00
|
|
|
/**
|
|
|
|
* xrdp: A Remote Desktop Protocol server.
|
|
|
|
*
|
2014-03-02 11:26:40 +04:00
|
|
|
* Copyright (C) Jay Sorg 2004-2014
|
2012-09-20 07:51:34 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2005-10-24 01:50:42 +04:00
|
|
|
|
|
|
|
#ifndef LOG_H
|
|
|
|
#define LOG_H
|
|
|
|
|
2008-02-21 01:02:24 +03:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2005-10-24 01:50:42 +04:00
|
|
|
#include "arch.h"
|
|
|
|
|
|
|
|
/* logging buffer size */
|
2006-06-04 16:10:02 +04:00
|
|
|
#define LOG_BUFFER_SIZE 1024
|
2005-10-24 01:50:42 +04:00
|
|
|
|
|
|
|
/* logging levels */
|
2012-06-04 23:51:22 +04:00
|
|
|
enum logLevels
|
|
|
|
{
|
2014-07-26 08:45:29 +04:00
|
|
|
LOG_LEVEL_ALWAYS = 0,
|
|
|
|
LOG_LEVEL_ERROR,
|
|
|
|
LOG_LEVEL_WARNING,
|
|
|
|
LOG_LEVEL_INFO,
|
|
|
|
LOG_LEVEL_DEBUG
|
2012-05-27 19:17:39 +04:00
|
|
|
};
|
2005-10-24 01:50:42 +04:00
|
|
|
|
|
|
|
/* startup return values */
|
2012-06-04 23:51:22 +04:00
|
|
|
enum logReturns
|
|
|
|
{
|
2014-07-26 08:45:29 +04:00
|
|
|
LOG_STARTUP_OK = 0,
|
|
|
|
LOG_ERROR_MALLOC,
|
|
|
|
LOG_ERROR_NULL_FILE,
|
|
|
|
LOG_ERROR_FILE_OPEN,
|
|
|
|
LOG_ERROR_NO_CFG,
|
|
|
|
LOG_ERROR_FILE_NOT_OPEN,
|
|
|
|
LOG_GENERAL_ERROR
|
2012-05-27 19:17:39 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SESMAN_CFG_LOGGING "Logging"
|
|
|
|
#define SESMAN_CFG_LOG_FILE "LogFile"
|
|
|
|
#define SESMAN_CFG_LOG_LEVEL "LogLevel"
|
|
|
|
#define SESMAN_CFG_LOG_ENABLE_SYSLOG "EnableSyslog"
|
|
|
|
#define SESMAN_CFG_LOG_SYSLOG_LEVEL "SyslogLevel"
|
2005-10-24 01:50:42 +04:00
|
|
|
|
2006-06-04 16:10:02 +04:00
|
|
|
/* enable threading */
|
|
|
|
/*#define LOG_ENABLE_THREAD*/
|
|
|
|
|
2005-10-24 01:50:42 +04:00
|
|
|
#ifdef DEBUG
|
2012-06-04 23:51:22 +04:00
|
|
|
#define LOG_DBG(args...) log_message(LOG_LEVEL_DEBUG, args);
|
2005-10-24 01:50:42 +04:00
|
|
|
#else
|
2012-06-04 23:51:22 +04:00
|
|
|
#define LOG_DBG(args...)
|
2005-10-24 01:50:42 +04:00
|
|
|
#endif
|
|
|
|
|
2005-11-05 09:04:40 +03:00
|
|
|
struct log_config
|
2005-10-24 01:50:42 +04:00
|
|
|
{
|
2016-06-22 02:30:17 +03:00
|
|
|
const char *program_name;
|
2014-07-26 08:45:29 +04:00
|
|
|
char *log_file;
|
|
|
|
int fd;
|
2016-07-08 04:47:31 +03:00
|
|
|
enum logLevels log_level;
|
2014-07-26 08:45:29 +04:00
|
|
|
int enable_syslog;
|
2016-07-08 04:47:31 +03:00
|
|
|
enum logLevels syslog_level;
|
2014-07-26 08:45:29 +04:00
|
|
|
pthread_mutex_t log_lock;
|
|
|
|
pthread_mutexattr_t log_lock_attr;
|
2005-10-24 01:50:42 +04:00
|
|
|
};
|
|
|
|
|
2012-05-27 19:17:39 +04:00
|
|
|
/* internal functions, only used in log.c if this ifdef is defined.*/
|
|
|
|
#ifdef LOGINTERNALSTUFF
|
2005-10-24 01:50:42 +04:00
|
|
|
|
|
|
|
/**
|
2005-11-05 09:04:40 +03:00
|
|
|
*
|
2006-06-04 16:10:02 +04:00
|
|
|
* @brief Starts the logging subsystem
|
2016-02-14 07:41:07 +03:00
|
|
|
* @param l_cfg logging system configuration
|
2005-10-24 01:50:42 +04:00
|
|
|
* @return
|
2005-11-05 09:04:40 +03:00
|
|
|
*
|
2005-10-24 01:50:42 +04:00
|
|
|
*/
|
2012-05-27 19:17:39 +04:00
|
|
|
enum logReturns DEFAULT_CC
|
2014-07-26 08:45:29 +04:00
|
|
|
internal_log_start(struct log_config *l_cfg);
|
2005-10-24 01:50:42 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2006-06-04 16:10:02 +04:00
|
|
|
* @brief Shuts down the logging subsystem
|
2008-02-21 01:02:24 +03:00
|
|
|
* @param l_cfg pointer to the logging subsystem to stop
|
2005-11-05 09:04:40 +03:00
|
|
|
*
|
2005-10-24 01:50:42 +04:00
|
|
|
*/
|
2012-05-27 19:17:39 +04:00
|
|
|
enum logReturns DEFAULT_CC
|
2014-07-26 08:45:29 +04:00
|
|
|
internal_log_end(struct log_config *l_cfg);
|
2012-05-27 19:17:39 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a log level to a string
|
2012-06-04 23:51:22 +04:00
|
|
|
* @param lvl, the loglevel
|
2012-05-27 19:17:39 +04:00
|
|
|
* @param str pointer where the string will be stored.
|
|
|
|
*/
|
2005-10-24 01:50:42 +04:00
|
|
|
void DEFAULT_CC
|
2014-07-26 08:45:29 +04:00
|
|
|
internal_log_lvl2str(const enum logLevels lvl, char *str);
|
2005-10-24 01:50:42 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2006-06-04 16:10:02 +04:00
|
|
|
* @brief Converts a string to a log level
|
|
|
|
* @param s The string to convert
|
|
|
|
* @return The corresponding level or LOG_LEVEL_DEBUG if error
|
2005-10-24 01:50:42 +04:00
|
|
|
*
|
|
|
|
*/
|
2012-05-27 19:17:39 +04:00
|
|
|
enum logLevels DEFAULT_CC
|
2016-10-17 09:14:06 +03:00
|
|
|
internal_log_text2level(const char *s);
|
2012-05-27 19:17:39 +04:00
|
|
|
|
|
|
|
/**
|
2012-06-04 23:51:22 +04:00
|
|
|
* A function that init our struct that holds all state and
|
2012-05-27 19:17:39 +04:00
|
|
|
* also init its content.
|
|
|
|
* @return LOG_STARTUP_OK or LOG_ERROR_MALLOC
|
|
|
|
*/
|
|
|
|
enum logReturns DEFAULT_CC
|
2012-06-04 23:51:22 +04:00
|
|
|
internalInitAndAllocStruct(void);
|
2012-05-27 19:17:39 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read configuration from a file and store the values in lists.
|
|
|
|
* @param file
|
|
|
|
* @param lc
|
|
|
|
* @param param_n
|
|
|
|
* @param param_v
|
|
|
|
* @param applicationName, the application name used in the log events.
|
2012-06-04 23:51:22 +04:00
|
|
|
* @return
|
2012-05-27 19:17:39 +04:00
|
|
|
*/
|
|
|
|
enum logReturns DEFAULT_CC
|
2014-07-26 08:45:29 +04:00
|
|
|
internal_config_read_logging(int file, struct log_config *lc,
|
|
|
|
struct list *param_n,
|
|
|
|
struct list *param_v,
|
2012-06-04 23:51:22 +04:00
|
|
|
const char *applicationName);
|
2012-05-27 19:17:39 +04:00
|
|
|
/*End of internal functions*/
|
|
|
|
#endif
|
|
|
|
/**
|
2012-06-04 23:51:22 +04:00
|
|
|
* This function initialize the log facilities according to the configuration
|
2012-05-27 19:17:39 +04:00
|
|
|
* file, that is described by the in parameter.
|
|
|
|
* @param iniFile
|
|
|
|
* @param applicationName, the name that is used in the log for the running application
|
|
|
|
* @return LOG_STARTUP_OK on success
|
|
|
|
*/
|
2012-06-04 23:51:22 +04:00
|
|
|
enum logReturns DEFAULT_CC
|
2014-07-26 08:45:29 +04:00
|
|
|
log_start(const char *iniFile, const char *applicationName);
|
2012-05-27 19:17:39 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An alternative log_start where the caller gives the params directly.
|
|
|
|
* @param iniParams
|
2012-06-04 23:51:22 +04:00
|
|
|
* @return
|
2012-05-27 19:17:39 +04:00
|
|
|
*/
|
|
|
|
enum logReturns DEFAULT_CC
|
|
|
|
log_start_from_param(const struct log_config *iniParams);
|
|
|
|
/**
|
|
|
|
* Function that terminates all logging
|
2012-06-04 23:51:22 +04:00
|
|
|
* @return
|
2012-05-27 19:17:39 +04:00
|
|
|
*/
|
2012-06-04 23:51:22 +04:00
|
|
|
enum logReturns DEFAULT_CC
|
|
|
|
log_end(void);
|
2012-05-27 19:17:39 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the log function that all files use to log an event.
|
|
|
|
* @param lvl, the loglevel
|
|
|
|
* @param msg, the logtext.
|
|
|
|
* @param ...
|
2012-06-04 23:51:22 +04:00
|
|
|
* @return
|
2012-05-27 19:17:39 +04:00
|
|
|
*/
|
2012-06-04 23:51:22 +04:00
|
|
|
enum logReturns DEFAULT_CC
|
2016-06-22 02:30:16 +03:00
|
|
|
log_message(const enum logLevels lvl, const char *msg, ...) printflike(2, 3);
|
2012-05-27 19:17:39 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function returns the configured file name for the logfile
|
|
|
|
* @param replybuf the buffer where the reply is stored
|
|
|
|
* @param bufsize how big is the reply buffer.
|
2012-06-04 23:51:22 +04:00
|
|
|
* @return
|
2012-05-27 19:17:39 +04:00
|
|
|
*/
|
|
|
|
char *getLogFile(char *replybuf, int bufsize);
|
2005-10-24 01:50:42 +04:00
|
|
|
#endif
|