LCOV - code coverage report
Current view: top level - shell/source/unix/misc - gnome-open-url.c (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 31 0.0 %
Date: 2014-11-03 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <stdlib.h>
      21             : #include <stdio.h>
      22             : #include <dlfcn.h>
      23             : #include <string.h>
      24             : #include <unistd.h>
      25             : 
      26             : typedef int   gboolean;
      27             : typedef char  gchar;
      28             : typedef struct _GError GError;
      29             : 
      30             : struct _GError
      31             : {
      32             :   int domain;
      33             :   int code;
      34             :   char *message;
      35             : };
      36             : 
      37             : typedef enum {
      38             :   GNOME_VFS_OK
      39             : } GnomeVFSResult;
      40             : 
      41             : /*
      42             :  * Wrapper function which extracs gnome_url_show from libgnome
      43             :  */
      44             : 
      45           0 : gboolean gnome_url_show (const char *url, GError **error)
      46             : {
      47           0 :     void* handle = dlopen("libgnomevfs-2.so.0", RTLD_LAZY);
      48           0 :     gboolean ret = 0;
      49             : 
      50             :     (void)error; /* avoid warning due to unused parameter */
      51             : 
      52           0 :     if( NULL != handle )
      53             :     {
      54           0 :         gboolean (* init) (void) =
      55           0 :             (gboolean (*) (void)) dlsym(handle, "gnome_vfs_init");
      56             : 
      57           0 :         if( NULL != init && init() )
      58             :         {
      59           0 :             GnomeVFSResult (* func) (const char *url) =
      60           0 :                 (GnomeVFSResult (*) (const char *)) dlsym(handle, "gnome_vfs_url_show");
      61             : 
      62           0 :             if( NULL != func )
      63           0 :                 ret = (GNOME_VFS_OK == func(url));
      64             :         }
      65             : 
      66           0 :         dlclose(handle);
      67             :     }
      68             : 
      69           0 :     return ret;
      70             : }
      71             : 
      72             : /*
      73             :  * The intended use of this tool is to pass the argument to
      74             :  * the gnome_show_url function of libgnome2.
      75             :  */
      76             : 
      77           0 : int main(int argc, char *argv[] )
      78             : {
      79           0 :     GError *error = NULL;
      80             :     char *fallback;
      81             :     char *idx;
      82           0 :     int retcode = -1;
      83             : 
      84           0 :     if( argc != 2 )
      85             :     {
      86           0 :         fprintf( stderr, "Usage: gnome-open-url <uri>\n" );
      87           0 :         return -1;
      88             :     }
      89             : 
      90           0 :     if( gnome_url_show(argv[1], &error) )
      91             :     {
      92           0 :         return 0;
      93             :     }
      94             : 
      95             :     /*
      96             :      * launch open-url command by replacing gnome-open-url from
      97             :      * the command line. This is the fallback when running on
      98             :      * remote machines with no GNOME installed.
      99             :      */
     100             : 
     101           0 :     fallback = strdup(argv[0]);
     102           0 :     idx = strstr(fallback, "gnome-open-url");
     103           0 :     if ( NULL != idx )
     104             :     {
     105             :         char *args[3];
     106           0 :         strncpy(idx, "open-url", 9);
     107           0 :         args[0] = fallback;
     108           0 :         args[1] = argv[1];
     109           0 :         args[2] = NULL;
     110           0 :         retcode = execv(fallback, args);
     111             :     }
     112           0 :     free(fallback);
     113             : 
     114           0 :     return retcode;
     115             : }
     116             : 
     117             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10