2013-03-05 13:16:36 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2014-07-28 20:23:03 +02:00
|
|
|
#ifndef INCLUDED_DESKTOP_INC_LIBREOFFICEKIT_INIT_H
|
|
|
|
#define INCLUDED_DESKTOP_INC_LIBREOFFICEKIT_INIT_H
|
|
|
|
|
|
|
|
#include "LibreOfficeKit.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
2014-10-23 21:59:17 +02:00
|
|
|
#if defined(__linux__) || defined (__FreeBSD_kernel__) || defined(_AIX)
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2013-03-05 16:19:58 +00:00
|
|
|
#include <stdio.h>
|
2014-07-16 19:36:53 +02:00
|
|
|
#include <stdlib.h>
|
2013-03-05 16:19:58 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <dlfcn.h>
|
2014-07-28 20:23:03 +02:00
|
|
|
#ifdef _AIX
|
2013-03-05 13:16:36 +00:00
|
|
|
# include <sys/ldr.h>
|
|
|
|
#endif
|
|
|
|
|
2014-07-16 19:36:53 +02:00
|
|
|
#define TARGET_LIB "lib" "sofficeapp" ".so"
|
2014-07-17 10:35:49 +02:00
|
|
|
#define TARGET_MERGED_LIB "lib" "mergedlo" ".so"
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2014-06-17 19:57:25 +01:00
|
|
|
typedef LibreOfficeKit *(HookFunction)( const char *install_path);
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2014-07-28 20:23:03 +02:00
|
|
|
static LibreOfficeKit *lok_init( const char *install_path )
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2013-11-15 12:09:10 +00:00
|
|
|
char *imp_lib;
|
2014-07-16 19:36:53 +02:00
|
|
|
size_t partial_length;
|
2013-11-15 12:09:10 +00:00
|
|
|
void *dlhandle;
|
|
|
|
HookFunction *pSym;
|
|
|
|
|
2014-07-16 19:36:53 +02:00
|
|
|
if (!install_path)
|
2013-03-05 13:16:36 +00:00
|
|
|
return NULL;
|
2014-07-16 19:36:53 +02:00
|
|
|
|
|
|
|
// allocate large enough buffer
|
|
|
|
partial_length = strlen(install_path);
|
|
|
|
imp_lib = (char *) malloc(partial_length + sizeof(TARGET_LIB) + sizeof(TARGET_MERGED_LIB) + 2);
|
|
|
|
if (!imp_lib)
|
2013-05-13 18:11:22 -05:00
|
|
|
{
|
|
|
|
fprintf( stderr, "failed to open library : not enough memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-11-15 12:09:10 +00:00
|
|
|
|
2014-07-16 19:36:53 +02:00
|
|
|
strcpy(imp_lib, install_path);
|
|
|
|
|
|
|
|
imp_lib[partial_length++] = '/';
|
|
|
|
strcpy(imp_lib + partial_length, TARGET_LIB);
|
2013-11-15 12:09:10 +00:00
|
|
|
|
2014-07-16 19:36:53 +02:00
|
|
|
dlhandle = dlopen(imp_lib, RTLD_LAZY);
|
|
|
|
if (!dlhandle)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2014-07-16 19:36:53 +02:00
|
|
|
strcpy(imp_lib + partial_length, TARGET_MERGED_LIB);
|
|
|
|
|
|
|
|
dlhandle = dlopen(imp_lib, RTLD_LAZY);
|
|
|
|
if (!dlhandle)
|
|
|
|
{
|
2014-07-28 20:23:03 +02:00
|
|
|
fprintf(stderr, "failed to open library '%s' or '%s' in '%s/'\n",
|
|
|
|
TARGET_LIB, TARGET_MERGED_LIB, install_path);
|
2014-07-16 19:36:53 +02:00
|
|
|
free(imp_lib);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
|
2014-06-17 15:13:33 +01:00
|
|
|
pSym = (HookFunction *) dlsym( dlhandle, "libreofficekit_hook" );
|
2014-07-16 19:36:53 +02:00
|
|
|
if (!pSym)
|
|
|
|
{
|
2013-03-05 13:16:36 +00:00
|
|
|
fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib );
|
2014-01-29 09:30:04 +00:00
|
|
|
dlclose( dlhandle );
|
2013-05-13 18:11:22 -05:00
|
|
|
free( imp_lib );
|
2013-03-05 13:16:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-03-05 16:40:01 +00:00
|
|
|
|
|
|
|
free( imp_lib );
|
2014-06-17 19:57:25 +01:00
|
|
|
return pSym( install_path );
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 20:23:03 +02:00
|
|
|
#endif // defined(__linux__) || defined(_AIX)
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2013-03-05 13:16:36 +00:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|