Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / olias_server.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 // $XConsortium: olias_server.cc /main/3 1996/06/11 17:30:16 cde-hal $
24 /*      Copyright (c) 1994 FUJITSU LIMITED      */
25 /*      All Rights Reserved                     */
26
27 /*
28  * Copyright (c) 1992 HAL Computer Systems International, Ltd.
29  * All rights reserved.  Unpublished -- rights reserved under
30  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
31  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
32  * OR DISCLOSURE.
33  * 
34  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
35  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
36  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
37  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
38  * INTERNATIONAL, LTD.
39  * 
40  *                         RESTRICTED RIGHTS LEGEND
41  * Use, duplication, or disclosure by the Government is subject
42  * to the restrictions as set forth in subparagraph (c)(l)(ii)
43  * of the Rights in Technical Data and Computer Software clause
44  * at DFARS 252.227-7013.
45  *
46  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
47  *                  1315 Dell Avenue
48  *                  Campbell, CA  95008
49  * 
50  */
51
52 #include "oliasdb/olias_server.h"
53
54 #ifdef DEMO_VERSION
55 void demo_version_check(info_lib* infolibptr)
56 {
57 #if 1
58    return;
59 #else
60    static char* demo_key = "DBzjcy94aK";
61    static char* demo_short_title = "02192ec285a9349ae85e3cc7";
62    static char* demo_long_title  = "1e87fe1d9c927e9e24be85e3cc733598faeda88101ecb253";
63
64    if ( infolibptr == 0 ) 
65      return;
66
67    info_base* x = 0;
68    int i = infolibptr -> first();
69
70    while ( i != 0 ) {
71       x = (*infolibptr)(i);
72
73       if ( x && (*(x  -> get_set(NODE_SET_POS))) -> count() > 0 ) 
74       {
75
76          node_smart_ptr n(x, demo_key);
77    
78          if ( strcmp(n.locator(), demo_key) != 0 ||
79               strcmp(n.short_title(), demo_short_title) != 0 ||
80               strcmp(n.long_title(), demo_long_title) != 0 
81          ) {
82               debug(cerr, n.locator());
83               debug(cerr, n.short_title());
84               debug(cerr, n.long_title());
85               throw(demoException(x -> get_base_path(), x -> get_base_name()));
86          }
87       }
88
89       infolibptr -> next(i);
90    }
91 #endif
92 }
93 #endif
94
95 olias_server::olias_server(
96             Boolean delayed_infolib_init,
97             char* selected_base_name,
98             char* x_info_lib_path
99                           ) :
100 server(x_info_lib_path)
101 {
102    managers::template_mgr -> insert_template(&dlp_template);
103    managers::template_mgr -> insert_template(&doc_template);
104    managers::template_mgr -> insert_template(&graphic_template);
105    managers::template_mgr -> insert_template(&locator_template); 
106    managers::template_mgr -> insert_template(&node_template); 
107    managers::template_mgr -> insert_template(&toc_template); 
108    managers::template_mgr -> insert_template(&mark_template); 
109    managers::template_mgr -> insert_template(&pref_template); 
110    managers::template_mgr -> insert_template(&stylesheet_template); 
111
112 ///////////////////////////////
113 //
114 ///////////////////////////////
115
116    info_base_set_names = new charPtr[7];
117
118    info_base_set_names[0] = NODE_SET_NAME;
119    info_base_set_names[1] = TOC_SET_NAME;
120    info_base_set_names[2] = LOCATOR_SET_NAME;
121    info_base_set_names[3] = GRAPHIC_SET_NAME,
122    info_base_set_names[4] = DOC_SET_NAME;
123    info_base_set_names[5] = STYLESHEET_SET_NAME;
124    info_base_set_names[6] = 0;
125
126    info_base_list_names = new charPtr[2];
127    info_base_list_names[0] = DLP_LIST_NAME;
128    info_base_list_names[1] = 0;
129
130    if ( delayed_infolib_init == false ) {
131       infolibptr = new info_lib(
132                        info_base_set_names, info_base_list_names,
133                        info_lib_dir, selected_base_name   
134                     );
135
136 #ifdef DEMO_VERSION
137       demo_version_check(infolibptr);
138 #endif
139
140    } else
141       infolibptr = 0;
142
143 }
144
145 olias_server::~olias_server()
146 {
147 }
148
149 void olias_server::init_infolib()
150 {
151    if ( infolibptr == 0 ) {
152       infolibptr = new info_lib(
153                        info_base_set_names, info_base_list_names,
154                        info_lib_dir, 0);
155
156 #ifdef DEMO_VERSION
157       demo_version_check(infolibptr);
158 #endif
159    }
160 }
161
162 info_base* olias_server::get_infobase(const char *locator_string, enum TestSelector sel)
163 {
164
165    if ( locator_string == 0 )
166       return 0;
167
168
169    info_base* ib = 0;
170
171    int ind = infolibptr -> first();
172
173    while ( ind ) {
174
175       ib =  (*infolibptr)(ind);
176
177       if (ib==0)
178          throw(stringException("null info_base ptr"));
179
180       try { // since an infobase may not have any graphics, we catch
181             // any exceptions there and try next infobase.
182
183          switch (sel) {
184           case LOC:
185            {
186             locator_smart_ptr loc(ib, locator_string);
187    
188 //fprintf(stderr, "inside-loc-string=%s\n", loc.inside_node_locator_str());
189 //fprintf(stderr, "loc-string=%s\n", locator_string);
190             if ( strcmp( loc.inside_node_locator_str(), locator_string) == 0 ) {
191                return ib;
192             }
193    
194            }
195           case GRA:
196            {
197             graphic_smart_ptr graphic(ib, locator_string);
198    
199             if ( strcmp( graphic.locator(), locator_string) == 0 ) {
200                return ib;
201             }
202            }
203          }
204       }
205
206       catch (mmdbException &,e)
207       {
208       } end_try;
209
210
211       infolibptr -> next(ind);
212    }
213
214    return 0;
215 }
216
217 info_base** olias_server::get_infobases(char **locator_strings, int count, enum TestSelector sel)
218 {
219    info_base** ibs = new info_basePtr[count];
220    for ( int i=0; i<count; ibs[i++] = 0 );
221
222    info_base* ib = 0;
223
224    int ind = infolibptr -> first();
225
226    while ( ind ) {
227
228       ib =  (*infolibptr)(ind);
229
230       if (ib == 0)
231          throw(stringException("null info_base ptr"));
232
233       for ( i=0; i<count; i++ ) {
234
235          try {
236    
237             if ( locator_strings[i] && ibs[i] == 0 ) {  
238               switch (sel) {
239                case LOC:
240               {
241                   locator_smart_ptr loc(ib, locator_strings[i]);
242    
243                   if ( strcmp( loc.inside_node_locator_str(), 
244                             locator_strings[i]) == 0 
245                   )
246                      ibs[i] = ib;
247                  }
248               break;
249    
250                case GRA:
251               {
252                   graphic_smart_ptr graphic(ib, locator_strings[i]);
253    
254                   if ( strcmp( graphic.locator(), 
255                             locator_strings[i]) == 0 
256                   )
257                      ibs[i] = ib;
258                  }
259               break;
260               }
261             }
262          }
263
264          catch (mmdbException &,e)
265          {
266          } end_try;
267
268       }
269
270       infolibptr -> next(ind);
271    }
272
273    return ibs;
274 }
275