Back to index

courier  0.68.2
comrwinstall.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2000 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #include      "courier.h"
00007 #include      "rw.h"
00008 #include      <stdio.h>
00009 #include      <string.h>
00010 #include      <stdlib.h>
00011 
00012 /*
00013        Install transport module libraries.
00014 
00015        Depending upon compilation options, transport module libraries are
00016        either linked with statically, or loaded as shared libraries.
00017 
00018        This module provides a unified interface for either installation
00019        method.
00020 
00021        The rw_init() function from each module is called, and a link list
00022        of struct rw_transport is created which includes a pointer to the
00023        result of each rw_init function call.
00024 
00025        First rw_install_start() is called to initialize the list.
00026 
00027        Then, rw_install is called with the name of each configured transport
00028        module, and it's rw_install and rw_init functions.  The module's
00029        rw_install function is called, and the result is saved in the
00030        rw_transport list.
00031 
00032        When all transport modules have been initialized, rw_install_init
00033        gets called, which goes through and calls the rw_init functions
00034        of every previously installed transport module libraries.
00035 */
00036 
00037 int rw_install_start()
00038 {
00039        if (rw_init_verbose_flag)
00040        {
00041               clog_msg_start_info();
00042               clog_msg_str(COURIER_COPYRIGHT);
00043               clog_msg_send();
00044               clog_msg_start_info();
00045               clog_msg_str("Installing [");
00046               clog_msg_uint(RW_VERLO);
00047               clog_msg_str("/");
00048               clog_msg_uint(RW_VERHI);
00049               clog_msg_str("]");
00050               clog_msg_send();
00051        }
00052        rw_transport_first=0;
00053        rw_transport_last=0;
00054        return (0);
00055 }
00056 
00057 int rw_install( const char *name,
00058        struct rw_list *(*rw_install)(const struct rw_install_info *),
00059        const char *(*rw_init)() )
00060 {
00061 struct rw_transport *t;
00062 struct rw_install_info install_info={RW_VERLO, RW_VERHI, COURIER_COPYRIGHT};
00063 
00064        if (rw_init_verbose_flag)
00065        {
00066               clog_msg_start_info();
00067               clog_msg_str("Installing ");
00068               clog_msg_str(name);
00069               clog_msg_send();
00070        }
00071 
00072        install_info.courier_home=courierdir();
00073        t=(struct rw_transport *)courier_malloc(sizeof(struct rw_transport));
00074        t->name=(char *)courier_malloc(strlen(name)+1);
00075        t->udata=0;
00076        if ((t->rw_ptr= (*rw_install)(&install_info)) == 0)
00077        {
00078               if (t->name)  free((void *)t->name);
00079               if (t)        free((void *)t);
00080               clog_msg_start_err();
00081               clog_msg_str("rw_install() failed, check for messages from the module.");
00082               clog_msg_send();
00083               return (-1);
00084        }
00085        strcpy(t->name, name);
00086        t->init=rw_init;
00087        if (rw_transport_last)      rw_transport_last->next=t;
00088        else   rw_transport_first=t;
00089        rw_transport_last=t;
00090        t->next=0;
00091        if (rw_init_verbose_flag)
00092        {
00093               clog_msg_start_info();
00094               clog_msg_str("Installed: ");
00095               clog_msg_str(t->rw_ptr->module_id);
00096               clog_msg_send();
00097        }
00098        return (0);
00099 }
00100 
00101 int rw_install_init()
00102 {
00103 struct rw_transport *t;
00104 const char *err;
00105 
00106        for (t=rw_transport_first; t; t=t->next)
00107        {
00108               if (rw_init_verbose_flag)
00109               {
00110                      clog_msg_start_info();
00111                      clog_msg_str("Initializing ");
00112                      clog_msg_str(t->name);
00113                      clog_msg_send();
00114               }
00115               if ((err=(*t->init)()) != 0)
00116               {
00117                      clog_msg_start_err();
00118                      clog_msg_str(err);
00119                      clog_msg_send();
00120                      return (-1);
00121               }
00122        }
00123        return (0);
00124 }