>From a52fc23cf0baa6aaa243e73b495650cb3b538c3c Mon Sep 17 00:00:00 2001
From: Rich Megginson <rmeggins@redhat.com>
Date: Thu, 16 Jun 2011 12:24:31 -0600
Subject: [PATCH] add support for different skins

These changes add support for different brand/version/other versions of
this and console packages.  The main place we get brand/version information
is from the .inf files.  The code will first look for a branded .inf file,
then for the default .inf file, for a given product.  This will allow
the skin version to override the default version.
Added support for a skinned help file.  The help cgi will first look for
skin-header.html, then fall back to header.html.
---
 admserv/cgi-src40/help.c                     |    9 ++++-
 admserv/newinst/src/30updateglobalpref.pl.in |    5 +-
 admserv/newinst/src/AdminMigration.pm.in     |   12 ++----
 admserv/newinst/src/AdminServer.pm.in        |    6 +--
 admserv/newinst/src/AdminUtil.pm.in          |   55 +++++++++++++++++---------
 5 files changed, 52 insertions(+), 35 deletions(-)

diff --git a/admserv/cgi-src40/help.c b/admserv/cgi-src40/help.c
index 1d59ba1..c136083 100644
--- a/admserv/cgi-src40/help.c
+++ b/admserv/cgi-src40/help.c
@@ -75,6 +75,7 @@
 #define HELPWIN_VAR    "HelpWindow"
 #define TOKEN_FILE     "index.map"
 #define HEADER_FILE    "header.html"
+#define SKIN_HEADER_FILE    "skin-header.html"
 #define FOOTER_FILE    "footer.html"
 #define HEAD_BLOCK     "<head>"
 #define FRAME_BLOCK    "<frame "
@@ -289,10 +290,16 @@ no_frame_help(char *name[], char *val[], int cnt, char *product, char *content)
    }
 
    /* read and flush the header to stdout */
+   /* try to read the "skin" header file first, then fall back to the default */
    safe_snprintf(path, sizeof(path), "%s%c%s%c%s%c%s", MANUALDIR, FILE_SEP, locale, FILE_SEP,
-                   product, FILE_SEP, HEADER_FILE);
+                   product, FILE_SEP, SKIN_HEADER_FILE);
    if (!(file = fopen(path, "r")))
    {
+       safe_snprintf(path, sizeof(path), "%s%c%s%c%s%c%s", MANUALDIR, FILE_SEP, locale, FILE_SEP,
+                     product, FILE_SEP, HEADER_FILE);
+   }
+   if (!file && (!(file = fopen(path, "r"))))
+   {
            safe_snprintf(base, sizeof(base), "unable to open file: %s", path);
            if (debugPrintout)
            {
diff --git a/admserv/newinst/src/30updateglobalpref.pl.in b/admserv/newinst/src/30updateglobalpref.pl.in
index cb5e86a..14dc910 100644
--- a/admserv/newinst/src/30updateglobalpref.pl.in
+++ b/admserv/newinst/src/30updateglobalpref.pl.in
@@ -29,8 +29,7 @@ use Mozilla::LDAP::API qw(:constant ldap_url_parse ldap_explode_dn);
 sub post {
     my ($inf, $configdir) = @_;
 
-    my $setupinf = new Inf("@infdir@/setup.inf");
-    my $admininf = new Inf("@infdir@/admin.inf");
+    my @infs = getInfs("setup", "admin");
     # there are several tokens in the map that we don't
     # use for 02globalpreferences - so just add dummy
     # values setupinf to make the map happy
@@ -40,7 +39,7 @@ sub post {
 
     my $upd = { path => '@ldifdir@/02globalpreferences.ldif.tmpl',
                 mapper => "@infdir@/configdsroot.map",
-                infary => [ $setupinf, $admininf ]
+                infary => \@infs
               };
                    
     return DSUpdate::applyLDIFUpdate($upd, $inf->{configdsconn}, $inf);
diff --git a/admserv/newinst/src/AdminMigration.pm.in b/admserv/newinst/src/AdminMigration.pm.in
index 5cfed1c..4ee9ab4 100644
--- a/admserv/newinst/src/AdminMigration.pm.in
+++ b/admserv/newinst/src/AdminMigration.pm.in
@@ -177,12 +177,11 @@ sub migratePset {
                      "@ldifdir@/21astasks.ldif.tmpl",
                      "@ldifdir@/22ascommands.ldif.tmpl"
                      );
-    my $setupinf = new Inf("@infdir@/setup.inf");
-    my $admininf = new Inf("@infdir@/admin.inf");
+    my @infs = getInfs("admin", "setup");
 
     my $mapper = new Inf("@infdir@/asmigrate.map");
 
-    $mapper = process_maptbl($mapper, \@errs, $inf, $admininf, $setupinf);
+    $mapper = process_maptbl($mapper, \@errs, $inf, @infs);
     if (!$mapper) {
         $mig->msg(@errs);
         $mig->msg($FATAL, 'error_creating_asmigration_maptbl');
@@ -263,13 +262,10 @@ sub updateConsoleInfo {
     # update the console info
     my @ldiffiles = ("@ldifdir@/02globalpreferences.ldif.tmpl"
                      );
-    my $setupinf = new Inf("@infdir@/setup.inf");
-    my $admininf = new Inf("@infdir@/admin.inf");
-    my $dsinf = new Inf("@infdir@/slapd.inf");
-
+    my @infs = getInfs("admin", "slapd", "setup");
     my $mapper = new Inf("@infdir@/updateconsoleinfo.map");
 
-    $mapper = process_maptbl($mapper, \@errs, $inf, $admininf, $dsinf, $setupinf);
+    $mapper = process_maptbl($mapper, \@errs, $inf, @infs);
     if (!$mapper) {
         $mig->msg(@errs);
         $mig->msg($FATAL, 'error_creating_updateconsole_maptbl');
diff --git a/admserv/newinst/src/AdminServer.pm.in b/admserv/newinst/src/AdminServer.pm.in
index 853fdd7..2056aa3 100644
--- a/admserv/newinst/src/AdminServer.pm.in
+++ b/admserv/newinst/src/AdminServer.pm.in
@@ -306,12 +306,10 @@ sub registerASWithConfigDS {
                      "@ldifdir@/21astasks.ldif.tmpl",
                      "@ldifdir@/22ascommands.ldif.tmpl"
                      );
-    my $setupinf = new Inf("@infdir@/setup.inf");
-    my $admininf = new Inf("@infdir@/admin.inf");
-
+    my @infs = getInfs("admin", "setup");
     my $mapper = new Inf("@infdir@/adminserver.map");
 
-    $mapper = process_maptbl($mapper, \@errs, $inf, $admininf, $setupinf);
+    $mapper = process_maptbl($mapper, \@errs, $inf, @infs);
     if (!$mapper or @errs) {
         $conn->close();
         $setup->msg(@errs);
diff --git a/admserv/newinst/src/AdminUtil.pm.in b/admserv/newinst/src/AdminUtil.pm.in
index 368983c..496e1ed 100644
--- a/admserv/newinst/src/AdminUtil.pm.in
+++ b/admserv/newinst/src/AdminUtil.pm.in
@@ -23,13 +23,13 @@ require Exporter;
                 updateAdmConf updateAdmpw updateLocalConf importCACert
                 getLocalConfigDS getPset registerDSWithConfigDS
                 registerManyDSWithConfigDS createSubDSNoConn
-                registerScatteredDSWithConfigDS
+                registerScatteredDSWithConfigDS getInfs
                 unregisterDSWithConfigDS isConfigDS addConfigACIsToSubDS);
 @EXPORT_OK = qw(getAdmConf getConfigDSConn createConfigDS createSubDS 
                 updateAdmConf updateAdmpw updateLocalConf importCACert
                 getLocalConfigDS getPset registerDSWithConfigDS
                 registerManyDSWithConfigDS createSubDSNoConn
-                registerScatteredDSWithConfigDS
+                registerScatteredDSWithConfigDS getInfs
                 unregisterDSWithConfigDS isConfigDS addConfigACIsToSubDS);
 
 # load perldap
@@ -287,12 +287,10 @@ sub createConfigDS {
                      '@ldifdir@/14dsmonitor.mod.tmpl',
                      '@ldifdir@/16dssuffixadmin.mod.tmpl'
                      );
-    my $setupinf = new Inf("@infdir@/setup.inf");
-    my $admininf = new Inf("@infdir@/admin.inf");
-    my $dsinf = new Inf("@infdir@/slapd.inf");
+    my @infs = getInfs("slapd", "admin", "setup");
     my $mapper = new Inf("@infdir@/configdsroot.map");
 
-    $mapper = process_maptbl($mapper, $errs, $inf, $dsinf, $admininf, $setupinf);
+    $mapper = process_maptbl($mapper, $errs, $inf, @infs);
     if (!$mapper or @{$errs}) {
         $conn->close();
         if (!@{$errs}) {
@@ -335,12 +333,10 @@ sub internalCreateSubDS {
         push @ldiffiles, '@ldifdir@/15dspta.mod.tmpl';
     }
     
-    my $setupinf = new Inf("@infdir@/setup.inf");
-    my $admininf = new Inf("@infdir@/admin.inf");
-    my $dsinf = new Inf("@infdir@/slapd.inf");
+    my @infs = getInfs("slapd", "admin", "setup");
     my $mapper = new Inf("@infdir@/dirserver.map");
 
-    $mapper = process_maptbl($mapper, $errs, $inf, $dsinf, $admininf, $setupinf);
+    $mapper = process_maptbl($mapper, $errs, $inf, @infs);
     if (!$mapper or @{$errs}) {
         $conn->close();
         if (!@{$errs}) {
@@ -418,12 +414,10 @@ sub addConfigACIsToSubDS {
     }
 
     my @ldiffiles = ('@ldifdir@/16dssuffixadmin.mod.tmpl');
-    my $setupinf = new Inf("@infdir@/setup.inf");
-    my $admininf = new Inf("@infdir@/admin.inf");
-    my $dsinf = new Inf("@infdir@/slapd.inf");
+    my @infs = getInfs("slapd", "admin", "setup");
     my $mapper = new Inf("@infdir@/dssuffixadmin.map");
 
-    $mapper = process_maptbl($mapper, $errs, $inf, $dsinf, $admininf, $setupinf);
+    $mapper = process_maptbl($mapper, $errs, $inf, @infs);
     if (!$mapper or @{$errs}) {
         $conn->close();
         if (!@{$errs}) {
@@ -868,13 +862,10 @@ sub registerDSWithConfigDSExt {
         # remove the Admin Server configuration entries
         @ldiffiles = ("@ldifdir@/10rm_dsdata.ldif.tmpl");
     }
-    my $setupinf = new Inf("@infdir@/setup.inf");
-    my $slapdinf = new Inf("@infdir@/slapd.inf");
-    my $admininf = new Inf("@infdir@/admin.inf");
-
+    my @infs = getInfs("slapd", "setup", "admin");
     my $mapper = new Inf("@infdir@/dirserver.map");
 
-    $mapper = process_maptbl($mapper, $errs, $inf, $instinf, $slapdinf, $setupinf, $admininf);
+    $mapper = process_maptbl($mapper, $errs, $inf, $instinf, @infs);
     if (!$mapper or @{$errs}) {
         if ($needclose) {
             $conn->close();
@@ -892,6 +883,32 @@ sub registerDSWithConfigDSExt {
     return @{$errs} ? 0 : 1;
 }
 
+# return Inf objects for the given names - the names correspond
+# to .inf file names in the infdir - the list will be ordered
+# so that brand specific names come before generic names -
+# it is assumed in .inf processing that if a value is found
+# in an earlier Inf later Infs will be ignored
+sub getInfs {
+    my @names = @_;
+    my @ary;
+    my @infs = glob("@infdir@/*.inf");
+    for my $name (@names) {
+        for my $inffile (@infs) {
+            if ($inffile =~ m,^@infdir@/.+-$name\.inf$,) {
+                # brand specific
+                debug(2, "Found brand specific inf file", $inffile);
+                push @ary, new Inf($inffile);
+            }
+        }
+    }
+    # added all brand specific inf files, if any - now add generic inf files
+    for my $name (@names) {
+        push @ary, new Inf("@infdir@/$name.inf");
+    }
+
+    return @ary;
+}
+
 1;
 
 # emacs settings
-- 
1.7.1

