1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * recptconfig.cpp --
|
---|
4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
5 | *
|
---|
6 | * PUT COPYRIGHT NOTICE HERE
|
---|
7 | *
|
---|
8 | * $Id: recptconfig.cpp 165 1999-02-21 22:33:58Z rjmcnab $
|
---|
9 | *
|
---|
10 | *********************************************************************/
|
---|
11 |
|
---|
12 | /*
|
---|
13 | $Log$
|
---|
14 | Revision 1.3 1999/02/21 22:33:57 rjmcnab
|
---|
15 |
|
---|
16 | Lots of stuff :-)
|
---|
17 |
|
---|
18 | Revision 1.2 1999/02/08 01:28:04 rjmcnab
|
---|
19 |
|
---|
20 | Got the receptionist producing something using the statusaction.
|
---|
21 |
|
---|
22 | Revision 1.1 1999/02/05 06:50:32 rjmcnab
|
---|
23 |
|
---|
24 | Initial revision.
|
---|
25 |
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | #include "recptconfig.h"
|
---|
30 | #include "fileutil.h"
|
---|
31 | #include "cfgread.h"
|
---|
32 |
|
---|
33 |
|
---|
34 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
35 | # include <ospace/std/iostream>
|
---|
36 | # include <ospace/std/fstream>
|
---|
37 | #elif defined(GSDL_USE_IOS_H)
|
---|
38 | # include <iostream.h>
|
---|
39 | # include <fstream.h>
|
---|
40 | #else
|
---|
41 | # include <iostream>
|
---|
42 | # include <fstream>
|
---|
43 | #endif
|
---|
44 |
|
---|
45 |
|
---|
46 | // reads site configuration file returning true on success
|
---|
47 | bool site_cfg_read (receptionist &recpt, const text_t &gsdlhome,
|
---|
48 | const text_t &collection, int &maxrequests) {
|
---|
49 |
|
---|
50 | maxrequests = 10000; // a reasonable default
|
---|
51 |
|
---|
52 | // Look for site.cfg in GSDLHOME/collect/collection-name/etc directory
|
---|
53 | // (if this is for a particular collection), and then GSDLHOME/etc.
|
---|
54 | text_t filename;
|
---|
55 | if (!collection.empty()) {
|
---|
56 | filename = filename_cat (gsdlhome, "collect");
|
---|
57 | filename = filename_cat (filename, collection);
|
---|
58 | filename = filename_cat (filename, "etc");
|
---|
59 | filename = filename_cat (filename, "site.cfg");
|
---|
60 | if (!file_exists (filename)) filename.clear();
|
---|
61 | }
|
---|
62 | if (filename.empty()) {
|
---|
63 | filename = filename_cat (gsdlhome, "etc");
|
---|
64 | filename = filename_cat (filename, "site.cfg");
|
---|
65 | if (!file_exists (filename)) return false;
|
---|
66 | }
|
---|
67 |
|
---|
68 | // read in the site configuration file
|
---|
69 | text_tarray cfgline;
|
---|
70 | text_t key;
|
---|
71 | char *cstr = filename.getcstr();
|
---|
72 | ifstream confin (cstr);
|
---|
73 | delete cstr;
|
---|
74 |
|
---|
75 | if (confin) {
|
---|
76 | while (read_cfg_line(confin, cfgline) >= 0) {
|
---|
77 | if (cfgline.size () >= 2) {
|
---|
78 | key = cfgline[0];
|
---|
79 | cfgline.erase(cfgline.begin());
|
---|
80 |
|
---|
81 | if (key == "maxrequests") {
|
---|
82 | maxrequests = cfgline[0].getint();
|
---|
83 | if (maxrequests < 1) maxrequests = 1;
|
---|
84 | }
|
---|
85 |
|
---|
86 | // configure the receptionist
|
---|
87 | recpt.configure (key, cfgline);
|
---|
88 | }
|
---|
89 | }
|
---|
90 | confin.close ();
|
---|
91 | return true;
|
---|
92 | }
|
---|
93 | return false;
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | // main_cfg_read reads either collect.cfg or main.cfg and returning
|
---|
98 | // true on success. It attempts to read collect.cfg first if a
|
---|
99 | // collection is specified and then it tries to read in main.cfg
|
---|
100 | bool main_cfg_read (receptionist &recpt, const text_t &gsdlhome,
|
---|
101 | const text_t &collection) {
|
---|
102 | // Look for site.cfg in GSDLHOME/collect/collection-name/etc directory
|
---|
103 | // (if this is for a particular collection), and then GSDLHOME/etc.
|
---|
104 | text_t filename;
|
---|
105 | if (!collection.empty()) {
|
---|
106 | filename = filename_cat (gsdlhome, "collect");
|
---|
107 | filename = filename_cat (filename, collection);
|
---|
108 | filename = filename_cat (filename, "etc");
|
---|
109 | filename = filename_cat (filename, "collect.cfg");
|
---|
110 | if (!file_exists (filename)) {
|
---|
111 | filename = filename_cat (gsdlhome, "etc");
|
---|
112 | filename = filename_cat (filename, "collect.cfg");
|
---|
113 | if (!file_exists (filename)) filename.clear();
|
---|
114 | }
|
---|
115 | }
|
---|
116 | if (filename.empty()) {
|
---|
117 | filename = filename_cat (gsdlhome, "etc");
|
---|
118 | filename = filename_cat (filename, "main.cfg");
|
---|
119 | if (!file_exists (filename)) return false;
|
---|
120 | }
|
---|
121 |
|
---|
122 | // read in the main configuration file
|
---|
123 | text_t key;
|
---|
124 | text_tarray cfgline;
|
---|
125 | char *cstr = filename.getcstr();
|
---|
126 | ifstream confin (cstr);
|
---|
127 | delete cstr;
|
---|
128 |
|
---|
129 | if (confin) {
|
---|
130 | while (read_cfg_line(confin, cfgline) >= 0) {
|
---|
131 | if (cfgline.size () >= 2) {
|
---|
132 | key = cfgline[0];
|
---|
133 | cfgline.erase(cfgline.begin());
|
---|
134 |
|
---|
135 | // configure the receptionist
|
---|
136 | recpt.configure (key, cfgline);
|
---|
137 | }
|
---|
138 | }
|
---|
139 | confin.close ();
|
---|
140 | return true;
|
---|
141 | }
|
---|
142 | return false;
|
---|
143 | }
|
---|