/*****************************************************************************

  POPular -- A POP3 server and proxy for large mail systems

  $Id: pdm.h,v 1.12 2001/03/23 10:56:44 sqrt Exp $

  http://www.remote.org/jochen/mail/popular/

******************************************************************************

  Copyright (C) 1999-2001  Jochen Topf <jochen@remote.org>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA

*****************************************************************************/

#ifndef _POPULAR_PDM_H
#define _POPULAR_PDM_H


#include "xlog.h"


typedef enum {
  pdmAccept,			/* Authentication accepted */
  pdmFail,			/* Authentication failed, but user exists */
  pdmUnknown,			/* Unknown user or namespace */
  pdmError			/* Internal error */
} pdm_result_t;


typedef enum {
  pdmFailUnknown,		/* Failed for unspecified reasons */
  pdmFailIP,			/* Not allowed from this IP */
  pdmFailProtocol,		/* Not allowed with this protocol */
  pdmFailPassword		/* Wrong password */
} pdm_fail_reason_t;


struct pdm_request {
  char *peer;
  protocol_t prot;
  char *user;
  char *pass;
  char *namespace;
};


struct pdm_data {
  int flags;
  pdm_fail_reason_t reason;
  char backend[MAXLEN_ID];
  char user[MAXLEN_USERNAME];
  char pass[MAXLEN_PASSWORD];
};


struct pdm_mvar {
  int *debug;
  void (*xlog_printf)(xlog_level_t level, int code, const char *format, ...);
};


struct pdm_module {
  struct pdm_module *next;
  char id[MAXBUF];
  char name[MAXBUF];
  void *lib;
  void *ctx;
  char *(*init)(int, char **, struct pdm_mvar *, void **);
  int (*close)(void *);
  char *(*args)(void *);
  int (*reload)(void *);
  pdm_result_t (*check)(void *, const struct pdm_request *, struct pdm_data *);
  pdm_result_t (*auth)(void *, const struct pdm_request *, struct pdm_data *);
};


/* in pdm.c */
struct pdm_module *pdm_attach(const char *dir, int argc, char *argv[]);
int pdm_detach(struct pdm_module *m);
pdm_result_t pdm_auth_user(const struct pdm_request *pr, struct pdm_data *pd);
int pdm_call_reload(struct pdm_module *m);
char *pdm_get_args(struct pdm_module *m);


/* in pdm modules */
char *pdm_init(int argc, char *argv[], struct pdm_mvar *mvar, void **pdmctx);
int pdm_close(void *pdmctx);
char *pdm_args(void *pdmctx);
int pdm_reload(void *pdmctx);
pdm_result_t pdm_check(void *pdmctx, const struct pdm_request *pdmr, struct pdm_data *pdmd);
pdm_result_t pdm_auth(void *pdmctx, const struct pdm_request *pdmr, struct pdm_data *pdmd);


/* debug macros */
#define PDM_DEBUG0(func, text) \
if (*(mv->debug) & DG_AUTH) do { \
  (*(mv->xlog_printf))(xlog_dbg, 0x0000, "PDM:" func ":" __FILE__ ":%d " text, __LINE__); \
} while (0)

/* This is not supported by older gccs :-(
#define PDM_DEBUGX(func, text, ...) \
if (*(mv->debug) & DG_AUTH) do { \
  (*(mv->xlog_printf))(xlog_dbg, 0x0000, "PDM:" func ":" __FILE__ ":%d " text, __LINE__, __VA_ARGS__); \
} while (0)
*/

#define PDM_DEBUG1(func, text, a1) \
if (*(mv->debug) & DG_AUTH) do { \
  (*(mv->xlog_printf))(xlog_dbg, 0x0000, "PDM:" func ":" __FILE__ ":%d " text, __LINE__, (a1)); \
} while (0)

#define PDM_DEBUG2(func, text, a1, a2) \
if (*(mv->debug) & DG_AUTH) do { \
  (*(mv->xlog_printf))(xlog_dbg, 0x0000, "PDM:" func ":" __FILE__ ":%d " text, __LINE__, (a1), (a2)); \
} while (0)

#define PDM_DEBUG3(func, text, a1, a2, a3) \
if (*(mv->debug) & DG_AUTH) do { \
  (*(mv->xlog_printf))(xlog_dbg, 0x0000, "PDM:" func ":" __FILE__ ":%d " text, __LINE__, (a1), (a2), (a3)); \
} while (0)

#define PDM_DEBUG4(func, text, a1, a2, a3, a4) \
if (*(mv->debug) & DG_AUTH) do { \
  (*(mv->xlog_printf))(xlog_dbg, 0x0000, "PDM:" func ":" __FILE__ ":%d " text, __LINE__, (a1), (a2), (a3), (a4)); \
} while (0)

#define PDM_DEBUG5(func, text, a1, a2, a3, a4, a5) \
if (*(mv->debug) & DG_AUTH) do { \
  (*(mv->xlog_printf))(xlog_dbg, 0x0000, "PDM:" func ":" __FILE__ ":%d " text, __LINE__, (a1), (a2), (a3), (a4), (a5)); \
} while (0)

#define PDM_DEBUG6(func, text, a1, a2, a3, a4, a5, a6) \
if (*(mv->debug) & DG_AUTH) do { \
  (*(mv->xlog_printf))(xlog_dbg, 0x0000, "PDM:" func ":" __FILE__ ":%d " text, __LINE__, (a1), (a2), (a3), (a4), (a5), (a6)); \
} while (0)


#endif  /* _POPULAR_PDM_H */


/** THE END *****************************************************************/


syntax highlighted by Code2HTML, v. 0.9.1