1  /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org 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 Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 
31 #include <rtl/ustring.hxx>
32 #include <osl/module.h>
33 #include <stdio.h>
34 #define  DECLARE_FN_POINTERS 1
35 #include "EApi.h"
36 static const char *eBookLibNames[] = {
37 	"libebook-1.2.so.9", // evolution-2.8
38 	"libebook-1.2.so.5", // evolution-2.4 and 2.6+
39 	"libebook-1.2.so.3", // evolution-2.2
40 	"libebook.so.8"      // evolution-2.0
41 };
42 
43 typedef void (*SymbolFunc) (void);
44 
45 #define SYM_MAP(a) { #a, (SymbolFunc *)&a }
46     static struct {
47 	const char *sym_name;
48 	SymbolFunc *ref_value;
49     } aApiMap[] = {
50 	SYM_MAP( e_contact_field_name ),
51 	SYM_MAP( e_contact_get ),
52 	SYM_MAP( e_contact_get_type ),
53 	SYM_MAP( e_contact_field_id ),
54 	SYM_MAP( e_source_peek_name ),
55 	SYM_MAP( e_source_get_property ),
56 	SYM_MAP( e_source_list_peek_groups ),
57 	SYM_MAP( e_source_group_peek_sources ),
58 	SYM_MAP( e_book_new ),
59 	SYM_MAP( e_book_open ),
60 	SYM_MAP( e_book_get_uri ),
61 	SYM_MAP( e_book_get_source ),
62 	SYM_MAP( e_book_get_addressbooks ),
63 	SYM_MAP( e_book_get_contacts ),
64 	SYM_MAP( e_book_authenticate_user ),
65 	SYM_MAP( e_book_query_field_test ),
66 	SYM_MAP( e_book_query_and ),
67 	SYM_MAP( e_book_query_or ),
68 	SYM_MAP( e_book_query_not ),
69 	SYM_MAP( e_book_query_ref ),
70 	SYM_MAP( e_book_query_unref ),
71 	SYM_MAP( e_book_query_from_string ),
72 	SYM_MAP( e_book_query_to_string ),
73 	SYM_MAP( e_book_query_field_exists ),
74 	SYM_MAP( e_source_group_peek_base_uri)
75     };
76 #undef SYM_MAP
77 
78 static bool
79 tryLink( oslModule &aModule, const char *pName )
80 {
81     for( guint i = 0; i < G_N_ELEMENTS( aApiMap ); i++ )
82     {
83 	SymbolFunc aMethod;
84 	aMethod = (SymbolFunc) osl_getFunctionSymbol
85 		( aModule, rtl::OUString::createFromAscii ( aApiMap[ i ].sym_name ).pData );
86 	if( !aMethod )
87 	{
88 	    fprintf( stderr, "Warning: missing symbol '%s' in '%s'",
89 		     aApiMap[ i ].sym_name, pName );
90 	    return false;
91 	}
92 	* aApiMap[ i ].ref_value = aMethod;
93     }
94     return true;
95 }
96 
97 bool EApiInit()
98 {
99     oslModule aModule;
100 
101     for( guint j = 0; j < G_N_ELEMENTS( eBookLibNames ); j++ )
102     {
103 		aModule = osl_loadModule( rtl::OUString::createFromAscii
104 								  ( eBookLibNames[ j ] ).pData,
105 								  SAL_LOADMODULE_DEFAULT );
106 		if( aModule)
107 		{
108 		    if ( tryLink( aModule, eBookLibNames[ j ] ) )
109 				return true;
110 		    osl_unloadModule( aModule );
111 		}
112     }
113     fprintf( stderr, "Can find no compliant libebook client libraries\n" );
114     return false;
115 }
116 
117 #if 0
118 // hjs: SOLARDEF does no longer exist please lookup the required
119 // defines in a regular compile line
120 /*
121  * Test code - enable &
122  *
123  * Compile with ( after source LinuxIntelEnv.Set.sh )
124    gcc $SOLARDEF -I $SOLARVER/$UPD/$INPATH/inc \
125      -I. `pkg-config --cflags --libs gobject-2.0` \
126      -L $SOLARVER/$UPD/$INPATH/lib -luno_sal -lstdc++ EApi.cxx
127  */
128 
129 int main( int argc, char **argv)
130 {
131     return EApiInit();
132 }
133 
134 #endif
135 
136