Back to index

courier  0.68.2
rw.h
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2009 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #ifndef       rw_h
00007 #define       rw_h
00008 
00009 #include      "courier.h"
00010 
00011 
00012 #ifdef __cplusplus
00013 extern "C" {
00014 #endif
00015 
00016 /* Install libraries */
00017 
00018 int rw_install_start();
00019 int rw_install( const char *name,
00020        struct rw_list *(*rw_install)(const struct rw_install_info *),
00021        const char *(*rw_init)() );
00022 int rw_install_init();
00023 
00024 /* Search for a rewriting function */
00025 
00026 /*struct rw_list *rw_search(const char *); */
00027 
00028 /* Rewrite address */
00029 
00030        /* Common rw_info structure */
00031 struct rw_info_rewrite {
00032        char   *buf;
00033        char   *errmsg;
00034        } ;
00035 
00036 struct rfc822t *rw_rewrite_tokenize(const char *);
00037 int rw_syntaxchk(struct rfc822token *);
00038 
00039 void rw_err_func(int, const char *, struct rw_info *);
00040        /*
00041        ** udata must point to rw_info_rewrite, where the error message
00042        ** is written to.
00043        */
00044 
00045 void rw_rewrite_print(struct rw_info *);
00046        /* Convert tokens to text, save in buf. */
00047 void rw_rewrite_chksyn_print(struct rw_info *);
00048        /* ... But first, check for syntax errors */
00049 void rw_rewrite_chksyn_at_ok_print(struct rw_info *);
00050        /* ... and allow leading @ in the address */
00051 
00052 /* Internal structure stores module list */
00053 
00054 extern struct rw_transport {
00055        struct rw_transport *next;
00056        char *name;
00057        struct rw_list *rw_ptr;
00058        const char *(*init)();
00059        void *udata;         /* For use by courierd */
00060        } *rw_transport_first, *rw_transport_last;
00061 
00062 void rw_searchdel(struct rw_info *,
00063               void (*)(struct rw_info *,
00064                      struct rw_transport *, const struct rfc822token *,
00065                      const struct rfc822token *));
00066 
00067 struct rw_transport *rw_search_transport(const char *);
00068 
00069 void rw_rewrite_module(struct rw_transport *, struct rw_info *,
00070        void (*)(struct rw_info *));       /* Call module from transport library */
00071 
00072 /* Rewrite RFC822 header: */
00073 
00074 char *rw_rewrite_header(struct rw_transport *,   /* Rewriting library */
00075        const char *,        /* header */
00076        int,                 /* flags/mode */
00077        struct rfc822token *,       /* sender */
00078        char **);            /* ptr to error message */
00079 
00080 char   *rw_rewrite_header_func(void (*rwfunc)(
00081                      struct rw_info *, void (*)(struct rw_info *), void *),
00082                                           /* Rewriting function */
00083        const char *,        /* See above */
00084        int,                 /* See above */
00085        struct rfc822token *,       /* See above */
00086        char **,             /* See above */
00087        void *);      /* Context ptr, passed as last arg to rwfunc */
00088 
00089 
00090 void rw_local_defaulthost(struct rw_info *, void (*)(struct rw_info *));
00091        /* Common rewriting function that appends the local domain to
00092        ** unqualified addresses. */
00093 
00094 
00095 /* Call rw_rewrite_header for the following headers: */
00096 
00097 /* If this is ever changed, don't forget to update submit.C */
00098 
00099 #if    HAVE_STRNCASECMP
00100 #define       DO_REWRITE_HEADER(l) \
00101        (strncasecmp((l),"to:", 3) == 0 || strncasecmp((l), "cc:", 3) == 0 || \
00102         strncasecmp((l), "from:", 5) == 0 || \
00103         strncasecmp((l), "reply-to:", 9) == 0)
00104 #else
00105 #define       DO_REWRITE_HEADER(l) \
00106        (strnicmp((l),"to:", 3) == 0 || strnicmp((l), "cc:", 3) == 0 || \
00107         strnicmp((l), "from:", 5) == 0 || \
00108         strnicmp((l), "reply-to:", 9) == 0)
00109 #endif
00110 
00111 /* Rewrite headers in an entire message */
00112 
00113 int rw_rewrite_msg(int,            /* Freshly open file descriptor
00114                             containing the message to rewrite */
00115 
00116        int (*)(const char *, unsigned, void *),
00117                             /*
00118                             ** This function is called repeatedly with
00119                             ** the contents of the rewritten message.
00120                             ** The function should non-0 if there was an
00121                             ** error while saving the contents of the
00122                             ** rewritten message.
00123                             */
00124        void (*)(struct rw_info *,
00125               void (*)(struct rw_info *), void *),
00126                             /* This function is called to rewrite a
00127                             ** single address.  It receives the standard
00128                             ** rwinfo structure, and must call the
00129                             ** supplied function pointer after doing
00130                             ** any rewriting.
00131                             */
00132        void * /*
00133               ** This pointer is forwarded as the last argument to the
00134               ** above two functions.
00135               */
00136        );
00137 
00138        /* rw_rewrite_msg returns 0, or the non-zero exit status if there
00139        ** was an error reported by the write func */
00140 
00141 struct rfc2045;
00142 
00143 int rw_rewrite_msg_7bit(int,
00144        struct rfc2045 *,
00145        int (*)(const char *, unsigned, void *),
00146        void (*)(struct rw_info *,
00147               void (*)(struct rw_info *), void *),
00148        void *
00149        );
00150 #ifdef __cplusplus
00151 }
00152 #endif
00153 #endif