Back to index

courier  0.68.2
comrwsearchdel.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 1999 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #include      "courier.h"
00007 #include      "rw.h"
00008 
00009 struct rw_searchdel_info {
00010        struct rw_transport *cur_transport;
00011        void   *save_udata;
00012        void   (*save_err_func)(int, const char *, struct rw_info *);
00013        void   (*del_func)(struct rw_info *,
00014               struct rw_transport *, const struct rfc822token *,
00015                      const struct rfc822token *);
00016 } ;
00017 
00018 static void do_next_rw(struct rw_info *, struct rw_searchdel_info *);
00019 
00020 static void del_err_func(int errnum, const char *errmsg, struct rw_info *i)
00021 {
00022 struct rw_searchdel_info *p=(struct rw_searchdel_info *)i->udata;
00023 
00024        i->udata=p->save_udata;
00025        i->err_func=p->save_err_func;
00026        (*i->err_func)(errnum, errmsg, i);
00027        i->err_func=del_err_func;
00028        i->udata=(void *)p;
00029 }
00030 
00031 static void found_delivery(struct rw_info *i, const struct rfc822token *host,
00032        const struct rfc822token *addr)
00033 {
00034 struct rw_searchdel_info *p=(struct rw_searchdel_info *)i->udata;
00035 
00036        i->udata=p->save_udata;
00037        i->err_func=p->save_err_func;
00038        (*p->del_func)(i, p->cur_transport, host, addr);
00039        i->err_func=del_err_func;
00040        i->udata=(void *)p;
00041 }
00042 
00043 static void call_next_rw(struct rw_info *i)
00044 {
00045 struct rw_searchdel_info *p=(struct rw_searchdel_info *)i->udata;
00046 
00047        p->cur_transport=p->cur_transport->next;
00048        do_next_rw(i, p);
00049 }
00050 
00051 static void do_next_rw(struct rw_info *i, struct rw_searchdel_info *di)
00052 {
00053        for ( ;di->cur_transport; di->cur_transport=di->cur_transport->next)
00054        {
00055               if (!di->cur_transport->rw_ptr)    continue;
00056               if (!di->cur_transport->rw_ptr->rewrite_del)     continue;
00057               (*di->cur_transport->rw_ptr->rewrite_del)(i, &call_next_rw,
00058                      &found_delivery);
00059               break;
00060        }
00061 }
00062 
00063 void rw_searchdel(struct rw_info *i,
00064               void (*func)(struct rw_info *,
00065                      struct rw_transport *, const struct rfc822token *,
00066                      const struct rfc822token *))
00067 {
00068 struct rw_searchdel_info rwsdi;
00069 
00070        rwsdi.cur_transport=rw_transport_first;
00071        rwsdi.save_udata=i->udata;
00072        rwsdi.save_err_func=i->err_func;
00073        i->udata= (void *)&rwsdi;
00074        i->err_func=del_err_func;
00075        rwsdi.del_func=func;
00076        do_next_rw(i, &rwsdi);
00077        i->udata=rwsdi.save_udata;
00078        i->err_func=rwsdi.save_err_func;
00079 }