1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 
27 #include <rtl/ustring.hxx>
28 #include <osl/module.h>
29 #include <stdio.h>
30 #define  DECLARE_FN_POINTERS 1
31 #include "EApi.h"
32 static const char *eBookLibNames[] = {
33 	"libebook-1.2.so.9", // evolution-2.8
34 	"libebook-1.2.so.5", // evolution-2.4 and 2.6+
35 	"libebook-1.2.so.3", // evolution-2.2
36 	"libebook.so.8"      // evolution-2.0
37 };
38 
39 typedef void (*SymbolFunc) (void);
40 
41 #define SYM_MAP(a) { #a, (SymbolFunc *)&a }
42     static struct {
43 	const char *sym_name;
44 	SymbolFunc *ref_value;
45     } aApiMap[] = {
46 	SYM_MAP( e_contact_field_name ),
47 	SYM_MAP( e_contact_get ),
48 	SYM_MAP( e_contact_get_type ),
49 	SYM_MAP( e_contact_field_id ),
50 	SYM_MAP( e_source_peek_name ),
51 	SYM_MAP( e_source_get_property ),
52 	SYM_MAP( e_source_list_peek_groups ),
53 	SYM_MAP( e_source_group_peek_sources ),
54 	SYM_MAP( e_book_new ),
55 	SYM_MAP( e_book_open ),
56 	SYM_MAP( e_book_get_uri ),
57 	SYM_MAP( e_book_get_source ),
58 	SYM_MAP( e_book_get_addressbooks ),
59 	SYM_MAP( e_book_get_contacts ),
60 	SYM_MAP( e_book_authenticate_user ),
61 	SYM_MAP( e_book_query_field_test ),
62 	SYM_MAP( e_book_query_and ),
63 	SYM_MAP( e_book_query_or ),
64 	SYM_MAP( e_book_query_not ),
65 	SYM_MAP( e_book_query_ref ),
66 	SYM_MAP( e_book_query_unref ),
67 	SYM_MAP( e_book_query_from_string ),
68 	SYM_MAP( e_book_query_to_string ),
69 	SYM_MAP( e_book_query_field_exists ),
70 	SYM_MAP( e_source_group_peek_base_uri)
71     };
72 #undef SYM_MAP
73 
74 static bool
tryLink(oslModule & aModule,const char * pName)75 tryLink( oslModule &aModule, const char *pName )
76 {
77     for( guint i = 0; i < G_N_ELEMENTS( aApiMap ); i++ )
78     {
79 	SymbolFunc aMethod;
80 	aMethod = (SymbolFunc) osl_getFunctionSymbol
81 		( aModule, rtl::OUString::createFromAscii ( aApiMap[ i ].sym_name ).pData );
82 	if( !aMethod )
83 	{
84 	    fprintf( stderr, "Warning: missing symbol '%s' in '%s'",
85 		     aApiMap[ i ].sym_name, pName );
86 	    return false;
87 	}
88 	* aApiMap[ i ].ref_value = aMethod;
89     }
90     return true;
91 }
92 
EApiInit()93 bool EApiInit()
94 {
95     oslModule aModule;
96 
97     for( guint j = 0; j < G_N_ELEMENTS( eBookLibNames ); j++ )
98     {
99 		aModule = osl_loadModule( rtl::OUString::createFromAscii
100 								  ( eBookLibNames[ j ] ).pData,
101 								  SAL_LOADMODULE_DEFAULT );
102 		if( aModule)
103 		{
104 		    if ( tryLink( aModule, eBookLibNames[ j ] ) )
105 				return true;
106 		    osl_unloadModule( aModule );
107 		}
108     }
109     fprintf( stderr, "Can find no compliant libebook client libraries\n" );
110     return false;
111 }
112 
113 #if 0
114 // hjs: SOLARDEF does no longer exist please lookup the required
115 // defines in a regular compile line
116 /*
117  * Test code - enable &
118  *
119  * Compile with ( after source LinuxIntelEnv.Set.sh )
120    gcc $SOLARDEF -I $SOLARVER/$UPD/$INPATH/inc \
121      -I. `pkg-config --cflags --libs gobject-2.0` \
122      -L $SOLARVER/$UPD/$INPATH/lib -luno_sal -lstdc++ EApi.cxx
123  */
124 
125 int main( int argc, char **argv)
126 {
127     return EApiInit();
128 }
129 
130 #endif
131 
132