LCOV - code coverage report
Current view: top level - libreoffice/svx/source/dialog - sendreportunx.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 113 0.0 %
Date: 2012-12-27 Functions: 0 9 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             : 
      21             : #include "docrecovery.hxx"
      22             : #include "osl/file.hxx"
      23             : #include "osl/process.h"
      24             : #include "rtl/bootstrap.hxx"
      25             : #include "rtl/strbuf.hxx"
      26             : #include "tools/appendunixshellword.hxx"
      27             : #include <string>
      28             : #include <stdio.h>
      29             : #include <stdlib.h>
      30             : #include <unistd.h>
      31             : #include <pwd.h>
      32             : 
      33             : #define RCFILE ".crash_reportrc"
      34             : 
      35             : using namespace ::std;
      36             : 
      37           0 : static const char *get_home_dir()
      38             : {
      39           0 :     struct passwd *ppwd = getpwuid( getuid() );
      40             : 
      41           0 :     return ppwd ? (ppwd->pw_dir ? ppwd->pw_dir : "/") : "/";
      42             : }
      43             : 
      44           0 : static bool read_line( FILE *fp, string& rLine )
      45             : {
      46             :     char szBuffer[1024];
      47           0 :     bool bSuccess = false;
      48           0 :     bool bEOL = false;
      49           0 :     string  line;
      50             : 
      51             : 
      52           0 :     while ( !bEOL && fgets( szBuffer, sizeof(szBuffer), fp ) )
      53             :     {
      54           0 :         int len = strlen(szBuffer);
      55             : 
      56           0 :         bSuccess = true;
      57             : 
      58           0 :         while ( len && szBuffer[len - 1] == '\n' )
      59             :         {
      60           0 :             szBuffer[--len] = 0;
      61           0 :             bEOL = true;
      62             :         }
      63             : 
      64           0 :         line.append( szBuffer );
      65             :     }
      66             : 
      67           0 :     rLine = line;
      68           0 :     return bSuccess;
      69             : }
      70             : 
      71           0 : static string trim_string( const string& rString )
      72             : {
      73           0 :     string temp = rString;
      74             : 
      75           0 :     while ( temp.length() && (temp[0] == ' ' || temp[0] == '\t') )
      76           0 :         temp.erase( 0, 1 );
      77             : 
      78           0 :     string::size_type   len = temp.length();
      79             : 
      80           0 :     while ( len && (temp[len-1] == ' ' || temp[len-1] == '\t') )
      81             :     {
      82           0 :         temp.erase( len - 1, 1 );
      83           0 :         len = temp.length();
      84             :     }
      85             : 
      86           0 :     return temp;
      87             : }
      88             : 
      89           0 : static string get_profile_string( const char *pFileName, const char *pSectionName, const char *pKeyName, const char *pDefault = NULL )
      90             : {
      91           0 :     FILE    *fp = fopen( pFileName, "r" );
      92           0 :     string  retValue = pDefault ? pDefault : "";
      93             : 
      94           0 :     if ( fp )
      95             :     {
      96           0 :         string line;
      97           0 :         string section;
      98             : 
      99           0 :         while ( read_line( fp, line ) )
     100             :         {
     101           0 :             line = trim_string( line );
     102             : 
     103           0 :             if ( line.length() && line[0] == '[' )
     104             :             {
     105           0 :                 line.erase( 0, 1 );
     106           0 :                 string::size_type end = line.find( ']', 0 );
     107             : 
     108           0 :                 if ( string::npos != end )
     109           0 :                     section = trim_string( line.substr( 0, end ) );
     110             :             }
     111             :             else
     112             :             {
     113             : 
     114           0 :                 string::size_type iEqualSign = line.find( '=', 0 );
     115             : 
     116           0 :                 if ( iEqualSign != string::npos )
     117             :                 {
     118           0 :                     string  keyname = line.substr( 0, iEqualSign );
     119           0 :                     keyname = trim_string( keyname );
     120             : 
     121           0 :                     string  value = line.substr( iEqualSign + 1, string::npos );
     122           0 :                     value = trim_string( value );
     123             : 
     124           0 :                     if (
     125           0 :                         0 == strcasecmp( section.c_str(), pSectionName ) &&
     126           0 :                         0 == strcasecmp( keyname.c_str(), pKeyName )
     127             :                          )
     128             :                     {
     129           0 :                         retValue = value;
     130             :                         break;
     131           0 :                     }
     132             :                 }
     133             :             }
     134             :         }
     135             : 
     136           0 :         fclose( fp );
     137             :     }
     138             : 
     139           0 :     return retValue;
     140             : }
     141             : 
     142           0 : static bool get_profile_bool( const char *pFileName, const char *pSectionName, const char *pKeyName )
     143             : {
     144           0 :     string  str = get_profile_string( pFileName, pSectionName, pKeyName );
     145             : 
     146           0 :     if ( !strcasecmp( str.c_str(), "true" ) )
     147           0 :         return true;
     148           0 :     return false;
     149             : }
     150             : 
     151           0 : static String get_profile_String( const char *pFileName, const char *pSectionName, const char *pKeyName, const char * = NULL )
     152             : {
     153           0 :     string  str = get_profile_string( pFileName, pSectionName, pKeyName );
     154           0 :     String  result( str.c_str(), RTL_TEXTENCODING_UTF8 );
     155             : 
     156           0 :     return result;
     157             : }
     158             : 
     159             : namespace svx{
     160             :     namespace DocRecovery{
     161             : 
     162           0 :         bool ErrorRepSendDialog::ReadParams()
     163             :         {
     164           0 :             string  sRCFile = get_home_dir();
     165             : 
     166           0 :             sRCFile += "/";
     167           0 :             sRCFile += string(RCFILE);
     168             : 
     169           0 :             maEMailAddrED.SetText( get_profile_String( sRCFile.c_str(), "Options", "ReturnAddress" ) );
     170           0 :             maParams.maHTTPProxyServer = get_profile_String( sRCFile.c_str(), "Options", "ProxyServer" );
     171           0 :             maParams.maHTTPProxyPort = get_profile_String( sRCFile.c_str(), "Options", "ProxyPort" );
     172           0 :             maParams.miHTTPConnectionType = get_profile_bool( sRCFile.c_str(), "Options", "UseProxy" ) ? 2 : 1;
     173           0 :             maContactCB.Check( get_profile_bool( sRCFile.c_str(), "Options", "AllowContact" ) );
     174             : 
     175           0 :             return true;
     176             :         }
     177             : 
     178           0 :         bool ErrorRepSendDialog::SaveParams()
     179             :         {
     180           0 :             bool success = false;
     181           0 :             string  sRCFile = get_home_dir();
     182             : 
     183           0 :             sRCFile += "/";
     184           0 :             sRCFile += string(RCFILE);
     185             : 
     186           0 :             FILE *fp = fopen( sRCFile.c_str(), "w" );
     187             : 
     188           0 :             if ( fp )
     189             :             {
     190           0 :                 fprintf( fp, "[Options]\n" );
     191           0 :                 fprintf( fp, "UseProxy=%s\n", 2 == maParams.miHTTPConnectionType ? "true" : "false" );
     192           0 :                 fprintf( fp, "ProxyServer=%s\n", rtl::OUStringToOString( maParams.maHTTPProxyServer, RTL_TEXTENCODING_UTF8 ).getStr() );
     193           0 :                 fprintf( fp, "ProxyPort=%s\n", rtl::OUStringToOString( maParams.maHTTPProxyPort, RTL_TEXTENCODING_UTF8 ).getStr() );
     194           0 :                 fprintf( fp, "ReturnAddress=%s\n", rtl::OUStringToOString( GetEMailAddress(), RTL_TEXTENCODING_UTF8 ).getStr() );
     195           0 :                 fprintf( fp, "AllowContact=%s\n", IsContactAllowed() ? "true" : "false" );
     196           0 :                 fclose( fp );
     197             :             }
     198             : 
     199           0 :             return success;
     200             :         }
     201             : 
     202           0 :         bool ErrorRepSendDialog::SendReport()
     203             :         {
     204           0 :             rtl::OUString sSubEnvVar(RTL_CONSTASCII_USTRINGPARAM("ERRORREPORT_SUBJECT"));
     205           0 :             rtl::OUString strSubject(GetDocType());
     206           0 :             osl_setEnvironment(sSubEnvVar.pData, strSubject.pData);
     207             : 
     208           0 :             char szBodyFile[L_tmpnam] = "";
     209           0 :             FILE *fp = fopen( tmpnam( szBodyFile ), "w" );
     210             : 
     211           0 :             if ( fp )
     212             :             {
     213           0 :                 rtl::OString strUTF8(rtl::OUStringToOString(GetUsing(), RTL_TEXTENCODING_UTF8));
     214             : 
     215           0 :                 size_t nWritten = fwrite(strUTF8.getStr(), 1, strUTF8.getLength(), fp);
     216           0 :                 OSL_VERIFY(nWritten == static_cast<size_t>(strUTF8.getLength()));
     217           0 :                 fclose( fp );
     218             : 
     219           0 :                 rtl::OUString sBodyEnvVar(RTL_CONSTASCII_USTRINGPARAM("ERRORREPORT_BODYFILE"));
     220             :                 rtl::OUString strBodyFile(rtl::OStringToOUString(rtl::OString(szBodyFile),
     221           0 :                     osl_getThreadTextEncoding()));
     222           0 :                 osl_setEnvironment(sBodyEnvVar.pData, strBodyFile.pData);
     223             :             }
     224             : 
     225           0 :             int ret = -1;
     226             :             rtl::OUString path1(
     227             :                 RTL_CONSTASCII_USTRINGPARAM(
     228           0 :                     "$BRAND_BASE_DIR/program/crashrep"));
     229           0 :             rtl::Bootstrap::expandMacros(path1);
     230           0 :             rtl::OString path2;
     231           0 :             if ((osl::FileBase::getSystemPathFromFileURL(path1, path1) ==
     232             :                  osl::FileBase::E_None) &&
     233             :                 path1.convertToString(
     234           0 :                     &path2, osl_getThreadTextEncoding(),
     235             :                     (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
     236           0 :                      RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
     237             :             {
     238           0 :                 rtl::OStringBuffer cmd;
     239           0 :                 tools::appendUnixShellWord(&cmd, path2);
     240           0 :                 cmd.append(RTL_CONSTASCII_STRINGPARAM(" -debug -load -send -noui"));
     241           0 :                 ret = system(cmd.getStr());
     242             :             }
     243             : 
     244           0 :             if ( szBodyFile[0] )
     245             :             {
     246           0 :                 unlink( szBodyFile );
     247             :             }
     248             : 
     249           0 :             return -1 != ret;
     250             :         }
     251             : 
     252             : 
     253             :     }   // namespace DocRecovery
     254             : }   // namespace svx
     255             : 
     256             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10