|
Packit |
34410b |
/*
|
|
Packit |
34410b |
*
|
|
Packit |
34410b |
* OBEX Server
|
|
Packit |
34410b |
*
|
|
Packit |
34410b |
* Copyright (C) 2007-2010 Marcel Holtmann <marcel@holtmann.org>
|
|
Packit |
34410b |
*
|
|
Packit |
34410b |
*
|
|
Packit |
34410b |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
34410b |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
34410b |
* the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
34410b |
* (at your option) any later version.
|
|
Packit |
34410b |
*
|
|
Packit |
34410b |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
34410b |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
34410b |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
34410b |
* GNU General Public License for more details.
|
|
Packit |
34410b |
*
|
|
Packit |
34410b |
* You should have received a copy of the GNU General Public License
|
|
Packit |
34410b |
* along with this program; if not, write to the Free Software
|
|
Packit |
34410b |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
34410b |
*
|
|
Packit |
34410b |
*/
|
|
Packit |
34410b |
|
|
Packit |
34410b |
#ifdef HAVE_CONFIG_H
|
|
Packit |
34410b |
#include <config.h>
|
|
Packit |
34410b |
#endif
|
|
Packit |
34410b |
|
|
Packit |
34410b |
#define _GNU_SOURCE
|
|
Packit |
34410b |
#include <stdio.h>
|
|
Packit |
34410b |
#include <stdarg.h>
|
|
Packit |
34410b |
#include <syslog.h>
|
|
Packit |
34410b |
|
|
Packit |
34410b |
#include <glib.h>
|
|
Packit |
34410b |
|
|
Packit |
34410b |
#include "log.h"
|
|
Packit |
34410b |
|
|
Packit |
34410b |
void info(const char *format, ...)
|
|
Packit |
34410b |
{
|
|
Packit |
34410b |
va_list ap;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
va_start(ap, format);
|
|
Packit |
34410b |
|
|
Packit |
34410b |
vsyslog(LOG_INFO, format, ap);
|
|
Packit |
34410b |
|
|
Packit |
34410b |
va_end(ap);
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
void error(const char *format, ...)
|
|
Packit |
34410b |
{
|
|
Packit |
34410b |
va_list ap;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
va_start(ap, format);
|
|
Packit |
34410b |
|
|
Packit |
34410b |
vsyslog(LOG_ERR, format, ap);
|
|
Packit |
34410b |
|
|
Packit |
34410b |
va_end(ap);
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
void obex_debug(const char *format, ...)
|
|
Packit |
34410b |
{
|
|
Packit |
34410b |
va_list ap;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
va_start(ap, format);
|
|
Packit |
34410b |
|
|
Packit |
34410b |
vsyslog(LOG_DEBUG, format, ap);
|
|
Packit |
34410b |
|
|
Packit |
34410b |
va_end(ap);
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
extern struct obex_debug_desc __start___debug[];
|
|
Packit |
34410b |
extern struct obex_debug_desc __stop___debug[];
|
|
Packit |
34410b |
|
|
Packit |
34410b |
static char **enabled = NULL;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
static gboolean is_enabled(struct obex_debug_desc *desc)
|
|
Packit |
34410b |
{
|
|
Packit |
34410b |
int i;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
if (enabled == NULL)
|
|
Packit |
34410b |
return 0;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
for (i = 0; enabled[i] != NULL; i++) {
|
|
Packit |
34410b |
if (desc->name != NULL && g_pattern_match_simple(enabled[i],
|
|
Packit |
34410b |
desc->name) == TRUE)
|
|
Packit |
34410b |
return 1;
|
|
Packit |
34410b |
if (desc->file != NULL && g_pattern_match_simple(enabled[i],
|
|
Packit |
34410b |
desc->file) == TRUE)
|
|
Packit |
34410b |
return 1;
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
return 0;
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
void __obex_log_enable_debug(void)
|
|
Packit |
34410b |
{
|
|
Packit |
34410b |
struct obex_debug_desc *desc;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
for (desc = __start___debug; desc < __stop___debug; desc++)
|
|
Packit |
34410b |
desc->flags |= OBEX_DEBUG_FLAG_PRINT;
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
void __obex_log_init(const char *debug, int detach)
|
|
Packit |
34410b |
{
|
|
Packit |
34410b |
int option = LOG_NDELAY | LOG_PID;
|
|
Packit |
34410b |
struct obex_debug_desc *desc;
|
|
Packit |
34410b |
const char *name = NULL, *file = NULL;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
if (debug != NULL)
|
|
Packit |
34410b |
enabled = g_strsplit_set(debug, ":, ", 0);
|
|
Packit |
34410b |
|
|
Packit |
34410b |
for (desc = __start___debug; desc < __stop___debug; desc++) {
|
|
Packit |
34410b |
if (file != NULL || name != NULL) {
|
|
Packit |
34410b |
if (g_strcmp0(desc->file, file) == 0) {
|
|
Packit |
34410b |
if (desc->name == NULL)
|
|
Packit |
34410b |
desc->name = name;
|
|
Packit |
34410b |
} else
|
|
Packit |
34410b |
file = NULL;
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
if (is_enabled(desc))
|
|
Packit |
34410b |
desc->flags |= OBEX_DEBUG_FLAG_PRINT;
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
if (!detach)
|
|
Packit |
34410b |
option |= LOG_PERROR;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
openlog("obexd", option, LOG_DAEMON);
|
|
Packit |
34410b |
|
|
Packit |
34410b |
info("OBEX daemon %s", VERSION);
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
void __obex_log_cleanup(void)
|
|
Packit |
34410b |
{
|
|
Packit |
34410b |
closelog();
|
|
Packit |
34410b |
|
|
Packit |
34410b |
g_strfreev(enabled);
|
|
Packit |
34410b |
}
|