Add Doxyfile for doxygen doc generation

This commit is contained in:
Ron Pedde 2004-11-12 06:38:05 +00:00
parent afa041790b
commit 71ec35efd3
4 changed files with 1362 additions and 95 deletions

1142
Doxyfile Normal file

File diff suppressed because it is too large Load Diff

114
src/err.c
View File

@ -19,6 +19,15 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* \file err.c
* Error handling, logging, and memory leak checking.
*
* Most of these functions should not be used directly. For the most
* part, they are hidden in macros like DPRINTF and MEMNOTIFY. The
* only function here that is really directly useable is log_setdest
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
@ -33,17 +42,25 @@
#include <syslog.h>
/* don't want to redefine malloc -- if doing memory debugging,
* this is the only file that *shouldn't* be redefining malloc and
* friends. Hence the define.
*/
#define __IN_ERR__
#include "err.h"
int err_debuglevel=0;
int err_logdestination=LOGDEST_STDERR;
FILE *err_file=NULL;
pthread_mutex_t err_mutex=PTHREAD_MUTEX_INITIALIZER;
int err_debuglevel=0; /**< current debuglevel, set from command line with -d */
static int err_logdestination=LOGDEST_STDERR; /**< current log destination */
static FILE *err_file=NULL; /**< if logging to file, the handle of that file */
static pthread_mutex_t err_mutex=PTHREAD_MUTEX_INITIALIZER; /**< for serializing log messages */
#ifdef DEBUG_MEMORY
/**
* Nodes for a linked list of in-use memory. Any malloc/strdup/etc
* calls get a new node of this type added to the ::err_leak list.
*/
typedef struct tag_err_leak {
void *ptr;
char *file;
@ -52,7 +69,7 @@ typedef struct tag_err_leak {
struct tag_err_leak *next;
} ERR_LEAK;
/** head of linked list of in-use memory */
ERR_LEAK err_leak = { NULL, NULL, 0, 0, NULL };
#endif
@ -60,12 +77,20 @@ ERR_LEAK err_leak = { NULL, NULL, 0, 0, NULL };
* Forwards
*/
int err_lock_mutex(void);
int err_unlock_mutex(void);
static int err_lock_mutex(void);
static int err_unlock_mutex(void);
/****************************************************
* log_err
****************************************************/
/**
* Write a printf-style formatted message to the log destination.
* This can be stderr, syslog, or a logfile, as determined by
* log_setdest. Note that this function should not be directly
* used, rather it should be used via the DPRINTF macro.
*
* \param level Level at which to log \ref log_levels
* \param fmt printf-style
*
* \relatesalso log_setdest
*/
void log_err(int level, char *fmt, ...)
{
va_list ap;
@ -109,8 +134,13 @@ void log_err(int level, char *fmt, ...)
}
}
/****************************************************
* log_setdest
/**
* Sets the log destination. (stderr, syslog, or logfile)
*
* \param app appname (used only for syslog destination)
* \param destination where to log to \ref log_dests "as defined in err.h"
*
* \relatesalso log_err
****************************************************/
void log_setdest(char *app, int destination) {
if(err_logdestination == destination)
@ -142,10 +172,12 @@ void log_setdest(char *app, int destination) {
}
/*
* err_lock
/**
* Lock the error mutex. This is used to serialize
* log messages, as well as protect access to the memory
* list, when memory debugging is enabled.
*
* Lock the error mutex
* \returns 0 on success, otherwise -1 with errno set
*/
int err_lock_mutex(void) {
int err;
@ -158,13 +190,10 @@ int err_lock_mutex(void) {
return 0;
}
/*
* err_unlock
*
/**
* Unlock the error mutex
*
* returns 0 on success,
* returns -1 on failure, with errno set
* \returns 0 on success, otherwise -1 with errno set
*/
int err_unlock_mutex(void) {
int err;
@ -179,9 +208,15 @@ int err_unlock_mutex(void) {
#ifdef DEBUG_MEMORY
/*
/**
* Let the leak detector know about a chunk of memory
* that needs to be freed, but came from an external library
* that needs to be freed, but came from an external library.
* Example: gdbm functions. Note that this should only
* be called via the MEMNOTIFY macro.
*
* \param file filled in from the MEMNOTIFY macro with __FILE__
* \param line filled in from the MEMNOTIFY macro with __LINE__
* \param ptr ptr to block of memory which must be freed
*/
void err_notify(char *file, int line, void *ptr) {
ERR_LEAK *pnew;
@ -207,10 +242,13 @@ void err_notify(char *file, int line, void *ptr) {
err_unlock_mutex();
}
/*
* err_malloc
/**
* malloc wrapper for leak checking. This never gets
* called directly, only via malloc.
*
* safe malloc
* \param file filled in via macro with __FILE__
* \param line filled in via macro with __LINE__
* \param size size of block to allocate
*/
void *err_malloc(char *file, int line, size_t size) {
ERR_LEAK *pnew;
@ -236,10 +274,13 @@ void *err_malloc(char *file, int line, size_t size) {
}
/*
* err_strdup
/**
* Memory check wrapper for strdup. This should not
* be called directly
*
* safe strdup
* \param file filled in via macro with __FILE__
* \param line filled in via macro with __LINE__
* \param str str to strdup
*/
char *err_strdup(char *file, int line, const char *str) {
void *pnew;
@ -252,10 +293,13 @@ char *err_strdup(char *file, int line, const char *str) {
return pnew;
}
/*
* err_free
/**
* Memory checking wrapper for free. This should not be
* called direclty.
*
* safe free
* \param file filled in by macro with __FILE__
* \param line filled in by macro with __LINE__
* \param ptr block of memory to free
*/
void err_free(char *file, int line, void *ptr) {
ERR_LEAK *current,*last;
@ -282,10 +326,10 @@ void err_free(char *file, int line, void *ptr) {
err_unlock_mutex();
}
/*
* void err_leakcheck
*
* Walk through the list of memory
/**
* Dumps the list of in-use memory. This walks the linked
* list created by the malloc and strdup wrappers, and dumps
* them to stdout.
*/
void err_leakcheck(void) {
ERR_LEAK *current;

View File

@ -19,25 +19,47 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* \file err.h
*
* Header file for err.c
*/
#ifndef __ERR_H__
#define __ERR_H__
#define LOGDEST_STDERR 0
#define LOGDEST_SYSLOG 1
#define LOGDEST_LOGFILE 2
/** @anchor log_dests */
#define LOGDEST_STDERR 0 /**< Log to stderr */
#define LOGDEST_SYSLOG 1 /**< Log to syslog */
#define LOGDEST_LOGFILE 2 /**< Log to logfile */
/** @anchor log_levels */
#define ERR_EXCESSIVE 10 /**< Logorrhea! */
#define ERR_DEBUG 9 /**< Way too verbose */
#define ERR_INFO 5 /**< Good info, not too much spam */
#define ERR_WARN 2 /**< Reasonably important, but not enough to log */
#define ERR_LOG 1 /**< Something that should go in a log file */
#define ERR_FATAL 0 /**< Log and force an exit */
/** @anchor log_categories */
#define LOG_CONFIG 0x0001 /**< configfile.c */
#define LOG_WEBSERVER 0x0002 /**< webserver.c */
#define LOG_DATABASE 0x0004 /**< db-* */
#define LOG_SCAN 0x0008 /**< mp3-scanner.c */
#define LOG_QUERY 0x0010 /**< query.c */
#define LOG_INDEX 0x0020 /**< daap.c */
#define LOG_BROWSE 0x0040 /**< daap.c, query.c */
#define LOG_PLAYLIST 0x0080 /**< playlist.c, lexer.l, parser.y */
#define ERR_DEBUG 9
#define ERR_INFO 5
#define ERR_WARN 2
#define ERR_LOG 1 /* should be logging at level 1 */
#define ERR_FATAL 0
extern int err_debuglevel;
extern int err_logdestination;
extern void log_err(int quit, char *fmt, ...);
extern void log_setdest(char *app, int destination);
/**
* Print a debugging or log message
*/
#ifdef DEBUG
# define DPRINTF(level, fmt, arg...) \
{ log_err(level,"%s, %d: ",__FILE__,__LINE__); log_err(level,fmt,##arg); }
@ -60,8 +82,10 @@ extern char *err_strdup(char *file, int line, const char *str);
extern void err_free(char *file, int line, void *ptr);
extern void err_notify(char *file, int line, void *ptr);
extern void err_leakcheck(void);
#else
/**
* Notify the leak checking system of externally allocated memory.
*/
# define MEMNOTIFY(x)
#endif /* DEBUG_MEMORY */
#endif /* __ERR_H__ */

View File

@ -19,6 +19,36 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* \file main.c
*
* Driver for mt-daapd, including the main() function. This
* is responsible for kicking off the initial mp3 scan, starting
* up the signal handler, starting up the webserver, and waiting
* around for external events to happen (like a request to rescan,
* or a background rescan to take place.)
*
* It also contains the daap handling callback for the webserver.
* This should almost certainly be somewhere else, and is in
* desparate need of refactoring, but somehow continues to be in
* this file.
*
* \todo Refactor daap_handler()
*/
/* \mainpage mt-daapd
* \section about_section About
*
* This is mt-daapd, an attempt to create an iTunes server for
* linux and other POSIXish systems. Maybe even Windows with cygwin,
* eventually.
*
* You might check these locations for more info:
* - <a href="http://sf.net/projects/mt-daapd">Project page on SourceForge</a>
* - <a href="http://mt-daapd.sf.net">Home page</a>
*
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
@ -54,39 +84,56 @@
# include "rend.h"
#endif
/**
* Where the default configfile is. On the NSLU2 running unslung,
* thats in /opt, not /etc. */
#ifndef DEFAULT_CONFIGFILE
#ifdef NSLU2
#define DEFAULT_CONFIGFILE "/opt/etc/mt-daapd.conf"
#define DEFAULT_CONFIGFILE "/opt/etc/mt-daapd/mt-daapd.conf"
#else
#define DEFAULT_CONFIGFILE "/etc/mt-daapd.conf"
#endif
#endif
/** Where to dump the pidfile */
#ifndef PIDFILE
#define PIDFILE "/var/run/mt-daapd.pid"
#endif
/** You say po-tay-to, I say po-tat-o */
#ifndef SIGCLD
# define SIGCLD SIGCHLD
#endif
#define MAIN_SLEEP_INTERVAL 2 /* seconds to sleep before checking for shutdown/reload */
#define MAIN_SLEEP_INTERVAL 2 /**< seconds to sleep before checking for shutdown/reload */
/*
* Globals
*/
CONFIG config;
CONFIG config; /**< Main configuration structure, as read from configfile */
/*
* Forwards
*/
int daemon_start(void);
void write_pid_file(void);
static int daemon_start(void);
static void write_pid_file(void);
static void usage(char *program);
static void *signal_handler(void *arg);
static int start_signal_handler(void);
/*
* daap_auth
/**
* Handles authentication for the daap server. This isn't the
* authenticator for the web admin page, but rather the iTunes
* authentication when trying to connect to the server. Note that most
* of this is actually handled in the web server registration, which
* decides when to apply the authentication or not. If you mess with
* when and where the webserver applies auth or not, you'll likely
* break something. It seems that some requests must be authed, and others
* not. If you apply authentication somewhere that iTunes doesn't expect
* it, it happily disconnects.
*
* Auth handler for the daap server
* \param username The username passed by iTunes
* \param password The password passed by iTunes
* \returns 1 if auth successful, 0 otherwise
*/
int daap_auth(char *username, char *password) {
if((password == NULL) &&
@ -99,10 +146,12 @@ int daap_auth(char *username, char *password) {
return !strcasecmp(password,config.readpassword);
}
/*
* daap_handler
/**
* This handles requests that are daap-related. For example,
* /server-info, /login, etc. This should really be split up
* into multiple functions, and perhaps moved into daap.c
*
* Handle daap-related web pages
* \param pwsc Webserver connection info, passed from the webserver
*/
void daap_handler(WS_CONNINFO *pwsc) {
int close;
@ -391,25 +440,9 @@ void daap_handler(WS_CONNINFO *pwsc) {
return;
}
/*
* sig_child
*
* reap children
/**
* Fork and exit. Stolen pretty much straight from Stevens.
*/
RETSIGTYPE sig_child(int signal)
{
int status;
while (wait(&status)) {
};
}
/*
* daemon_start
*
* This is pretty much stolen straight from Stevens
*/
int daemon_start(void) {
int childpid, fd;
@ -458,12 +491,11 @@ int daemon_start(void) {
return 0;
}
/*
* usage
/**
* Print usage information to stdout
*
* print usage message
* \param program name of program (argv[0])
*/
void usage(char *program) {
printf("Usage: %s [options]\n\n",program);
printf("Options:\n");
@ -475,10 +507,13 @@ void usage(char *program) {
printf("\n\n");
}
/*
* drop_privs
/**
* Drop privs. This allows mt-daapd to run as a non-privileged user.
* Hopefully this will limit the damage it could do if exploited
* remotely. Note that only the user need be specified. GID
* is set to the primary group of the user.
*
* drop privs to a specific user
* \param user user to run as (or UID)
*/
int drop_privs(char *user) {
int err;
@ -513,10 +548,15 @@ int drop_privs(char *user) {
return 0;
}
/*
* signal_handler
*
* This thread merely spins waiting for signals
/**
* Wait for signals and flag the main process. This is
* a thread handler for the signal processing thread. It
* does absolutely nothing except wait for signals. The rest
* of the threads are running with signals blocked, so this thread
* is guaranteed to catch all the signals. It sets flags in
* the config structure that the main thread looks for. Specifically,
* the stop flag (from an INT signal), and the reload flag (from HUP).
* \param arg NULL, but required of a thread procedure
*/
void *signal_handler(void *arg) {
sigset_t intmask;
@ -562,10 +602,12 @@ void *signal_handler(void *arg) {
return NULL;
}
/*
* start_signal_handler
/**
* Block signals, then start the signal handler. The
* signal handler started by spawning a new thread on
* signal_handler().
*
* Block signals and set up the signal handler
* \returns 0 on success, -1 with errno set otherwise
*/
int start_signal_handler(void) {
int error;
@ -591,6 +633,24 @@ int start_signal_handler(void) {
return 0;
}
/**
* Kick off the daap server and wait for events.
*
* This starts the initial db scan, sets up the signal
* handling, starts the webserver, then sits back and waits
* for events, as notified by the signal handler and the
* web interface. These events are communicated via flags
* in the config structure.
*
* \param argc count of command line arguments
* \param argv command line argument pointers
* \returns 0 on success, -1 otherwise
*
* \todo split out a ws_init and ws_start, so that the
* web space handlers can be registered before the webserver
* starts.
*
*/
int main(int argc, char *argv[]) {
int option;
char *configfile=DEFAULT_CONFIGFILE;
@ -810,13 +870,10 @@ int main(int argc, char *argv[]) {
return EXIT_SUCCESS;
}
/*
* write_pid_file
*
* Assumes we haven't dropped privs yet
/**
* Dump a pidfile in the file specified by PIDFILE
*/
void write_pid_file(void)
{
void write_pid_file(void) {
FILE* fp;
int fd;