1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * colservrconfig.cpp --
|
---|
4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
5 | *
|
---|
6 | * A component of the Greenstone digital library software
|
---|
7 | * from the New Zealand Digital Library Project at the
|
---|
8 | * University of Waikato, New Zealand.
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *
|
---|
24 | * $Id: colservrconfig.cpp 534 1999-09-07 04:57:43Z sjboddie $
|
---|
25 | *
|
---|
26 | *********************************************************************/
|
---|
27 |
|
---|
28 | /*
|
---|
29 | $Log$
|
---|
30 | Revision 1.2 1999/09/07 04:57:20 sjboddie
|
---|
31 | added gpl notice
|
---|
32 |
|
---|
33 | Revision 1.1 1999/02/21 22:32:55 rjmcnab
|
---|
34 |
|
---|
35 | Initial revision.
|
---|
36 |
|
---|
37 | */
|
---|
38 |
|
---|
39 |
|
---|
40 | #include "colservrconfig.h"
|
---|
41 | #include "fileutil.h"
|
---|
42 | #include "cfgread.h"
|
---|
43 |
|
---|
44 |
|
---|
45 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
46 | # include <ospace/std/iostream>
|
---|
47 | # include <ospace/std/fstream>
|
---|
48 | #elif defined(GSDL_USE_IOS_H)
|
---|
49 | # include <iostream.h>
|
---|
50 | # include <fstream.h>
|
---|
51 | #else
|
---|
52 | # include <iostream>
|
---|
53 | # include <fstream>
|
---|
54 | #endif
|
---|
55 |
|
---|
56 | // collect_cfg_read reads collect.cfg returning true on success.
|
---|
57 | bool collect_cfg_read (collectserver &cserver, const text_t &gsdlhome,
|
---|
58 | const text_t &collection) {
|
---|
59 | text_t filename = filename_cat (gsdlhome, "collect");
|
---|
60 | filename = filename_cat (filename, collection);
|
---|
61 | filename = filename_cat (filename, "etc");
|
---|
62 | filename = filename_cat (filename, "collect.cfg");
|
---|
63 | if (!file_exists (filename)) {
|
---|
64 | filename = filename_cat (gsdlhome, "etc");
|
---|
65 | filename = filename_cat (filename, "collect.cfg");
|
---|
66 | if (!file_exists (filename)) return false;
|
---|
67 | }
|
---|
68 |
|
---|
69 | // read in the collection configuration file
|
---|
70 | text_t key;
|
---|
71 | text_tarray cfgline;
|
---|
72 | char *cstr = filename.getcstr();
|
---|
73 | ifstream confin (cstr);
|
---|
74 | delete cstr;
|
---|
75 |
|
---|
76 | if (confin) {
|
---|
77 | while (read_cfg_line(confin, cfgline) >= 0) {
|
---|
78 | if (cfgline.size () >= 2) {
|
---|
79 | key = cfgline[0];
|
---|
80 | cfgline.erase(cfgline.begin());
|
---|
81 |
|
---|
82 | // configure the collection server
|
---|
83 | cserver.configure (key, cfgline);
|
---|
84 | }
|
---|
85 | }
|
---|
86 | confin.close ();
|
---|
87 | return true;
|
---|
88 | }
|
---|
89 | return false;
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | // build_cfg_read reads build.cfg and returns true on success.
|
---|
94 | bool build_cfg_read (collectserver &cserver, const text_t &gsdlhome,
|
---|
95 | const text_t &collection) {
|
---|
96 | text_t filename = filename_cat (gsdlhome, "collect");
|
---|
97 | filename = filename_cat (filename, collection);
|
---|
98 | filename = filename_cat (filename, "index");
|
---|
99 |
|
---|
100 | filename = filename_cat (filename, "build.cfg");
|
---|
101 | if (!file_exists (filename)) {
|
---|
102 | filename = filename_cat (gsdlhome, "index");
|
---|
103 | filename = filename_cat (filename, "build.cfg");
|
---|
104 | if (!file_exists (filename)) return false;
|
---|
105 | }
|
---|
106 |
|
---|
107 | // read in the build configuration file
|
---|
108 | text_t key;
|
---|
109 | text_tarray cfgline;
|
---|
110 | char *cstr = filename.getcstr();
|
---|
111 | ifstream confin (cstr);
|
---|
112 | delete cstr;
|
---|
113 |
|
---|
114 | if (confin) {
|
---|
115 | while (read_cfg_line(confin, cfgline) >= 0) {
|
---|
116 | if (cfgline.size () >= 2) {
|
---|
117 | key = cfgline[0];
|
---|
118 | cfgline.erase(cfgline.begin());
|
---|
119 |
|
---|
120 | // configure the collection server
|
---|
121 | cserver.configure (key, cfgline);
|
---|
122 | }
|
---|
123 | }
|
---|
124 | confin.close ();
|
---|
125 | return true;
|
---|
126 | }
|
---|
127 | return false;
|
---|
128 | }
|
---|
129 |
|
---|