LCOV - code coverage report
Current view: top level - ucb/source/ucp/gio - gio_mount.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 85 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 7 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 "gio_mount.hxx"
      21             : #include <ucbhelper/simpleauthenticationrequest.hxx>
      22             : #include <string.h>
      23             : 
      24             : #ifdef __GNUC__
      25             : #pragma GCC diagnostic push
      26             : #pragma GCC diagnostic ignored "-Wunused-function"
      27             : #endif
      28           0 : G_DEFINE_TYPE (OOoMountOperation, ooo_mount_operation, G_TYPE_MOUNT_OPERATION);
      29             : #ifdef __GNUC__
      30             : #pragma GCC diagnostic pop
      31             : #endif
      32             : 
      33             : static void ooo_mount_operation_ask_password (GMountOperation   *op,
      34             :     const char *message, const char *default_user, const char *default_domain,
      35             :     GAskPasswordFlags flags);
      36             : 
      37           0 : static void ooo_mount_operation_init (OOoMountOperation *op)
      38             : {
      39           0 :     op->m_pPrevPassword = NULL;
      40           0 :     op->m_pPrevUsername = NULL;
      41           0 : }
      42             : 
      43           0 : static void ooo_mount_operation_finalize (GObject *object)
      44             : {
      45           0 :     OOoMountOperation *mount_op = OOO_MOUNT_OPERATION (object);
      46           0 :     if (mount_op->m_pPrevUsername)
      47           0 :         free(mount_op->m_pPrevUsername);
      48           0 :     if (mount_op->m_pPrevPassword)
      49           0 :         free(mount_op->m_pPrevPassword);
      50             : 
      51           0 :     G_OBJECT_CLASS (ooo_mount_operation_parent_class)->finalize (object);
      52           0 : }
      53             : 
      54           0 : static void ooo_mount_operation_class_init (OOoMountOperationClass *klass)
      55             : {
      56           0 :     GObjectClass *object_class = G_OBJECT_CLASS (klass);
      57           0 :     object_class->finalize = ooo_mount_operation_finalize;
      58             : 
      59           0 :     GMountOperationClass *mount_op_class = G_MOUNT_OPERATION_CLASS (klass);
      60           0 :     mount_op_class->ask_password = ooo_mount_operation_ask_password;
      61           0 : }
      62             : 
      63             : using namespace com::sun::star;
      64             : 
      65           0 : static void ooo_mount_operation_ask_password (GMountOperation *op,
      66             :     const char * /*message*/, const char *default_user,
      67             :     const char *default_domain, GAskPasswordFlags flags)
      68             : {
      69           0 :     uno::Reference< task::XInteractionHandler > xIH;
      70             : 
      71           0 :     OOoMountOperation *pThis = reinterpret_cast<OOoMountOperation*>(op);
      72             : 
      73           0 :     const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > &xEnv = *(pThis->pEnv);
      74             : 
      75           0 :     if (xEnv.is())
      76           0 :       xIH = xEnv->getInteractionHandler();
      77             : 
      78           0 :     if (!xIH.is())
      79             :     {
      80           0 :         g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
      81           0 :         return;
      82             :     }
      83             : 
      84           0 :     OUString aHostName, aDomain, aUserName, aPassword;
      85             : 
      86             :     ucbhelper::SimpleAuthenticationRequest::EntityType eUserName =
      87           0 :         (flags & G_ASK_PASSWORD_NEED_USERNAME)
      88             :           ? ucbhelper::SimpleAuthenticationRequest::ENTITY_MODIFY
      89           0 :           : ucbhelper::SimpleAuthenticationRequest::ENTITY_NA;
      90             : 
      91           0 :     if (default_user)
      92           0 :         aUserName = OUString(default_user, strlen(default_user), RTL_TEXTENCODING_UTF8);
      93             : 
      94             :     ucbhelper::SimpleAuthenticationRequest::EntityType ePassword =
      95           0 :         (flags & G_ASK_PASSWORD_NEED_PASSWORD)
      96             :           ? ucbhelper::SimpleAuthenticationRequest::ENTITY_MODIFY
      97           0 :           : ucbhelper::SimpleAuthenticationRequest::ENTITY_NA;
      98             : 
      99           0 :     OUString aPrevPassword, aPrevUsername;
     100           0 :     if (pThis->m_pPrevUsername)
     101           0 :         aPrevUsername = OUString(pThis->m_pPrevUsername, strlen(pThis->m_pPrevUsername), RTL_TEXTENCODING_UTF8);
     102           0 :     if (pThis->m_pPrevPassword)
     103           0 :         aPrevPassword = OUString(pThis->m_pPrevPassword, strlen(pThis->m_pPrevPassword), RTL_TEXTENCODING_UTF8);
     104             : 
     105             :     //The damn dialog is stupidly broken, so do like webdav, i.e. "#102871#"
     106           0 :     if ( aUserName.isEmpty() )
     107           0 :         aUserName = aPrevUsername;
     108             : 
     109           0 :     if ( aPassword.isEmpty() )
     110           0 :         aPassword = aPrevPassword;
     111             : 
     112             :     ucbhelper::SimpleAuthenticationRequest::EntityType eDomain =
     113           0 :         (flags & G_ASK_PASSWORD_NEED_DOMAIN)
     114             :           ? ucbhelper::SimpleAuthenticationRequest::ENTITY_MODIFY
     115           0 :           : ucbhelper::SimpleAuthenticationRequest::ENTITY_NA;
     116             : 
     117           0 :     if (default_domain)
     118           0 :         aDomain = OUString(default_domain, strlen(default_domain), RTL_TEXTENCODING_UTF8);
     119             : 
     120             :     uno::Reference< ucbhelper::SimpleAuthenticationRequest > xRequest
     121           0 :         = new ucbhelper::SimpleAuthenticationRequest (OUString() /* FIXME: provide URL here */, aHostName, eDomain, aDomain, eUserName, aUserName, ePassword, aPassword);
     122             : 
     123           0 :     xIH->handle( xRequest.get() );
     124             : 
     125           0 :     rtl::Reference< ucbhelper::InteractionContinuation > xSelection = xRequest->getSelection();
     126             : 
     127           0 :     if ( !xSelection.is() )
     128             :     {
     129           0 :         g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
     130           0 :         return;
     131             :     }
     132             : 
     133           0 :     uno::Reference< task::XInteractionAbort > xAbort(xSelection.get(), uno::UNO_QUERY );
     134           0 :     if ( xAbort.is() )
     135             :     {
     136           0 :         g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
     137           0 :         return;
     138             :     }
     139             : 
     140           0 :     const rtl::Reference< ucbhelper::InteractionSupplyAuthentication > & xSupp = xRequest->getAuthenticationSupplier();
     141           0 :     aUserName = xSupp->getUserName();
     142           0 :     aPassword = xSupp->getPassword();
     143             : 
     144           0 :     if (flags & G_ASK_PASSWORD_NEED_USERNAME)
     145           0 :         g_mount_operation_set_username(op, OUStringToOString(aUserName, RTL_TEXTENCODING_UTF8).getStr());
     146             : 
     147           0 :     if (flags & G_ASK_PASSWORD_NEED_PASSWORD)
     148           0 :         g_mount_operation_set_password(op, OUStringToOString(aPassword, RTL_TEXTENCODING_UTF8).getStr());
     149             : 
     150           0 :     if (flags & G_ASK_PASSWORD_NEED_DOMAIN)
     151           0 :         g_mount_operation_set_domain(op, OUStringToOString(xSupp->getRealm(), RTL_TEXTENCODING_UTF8).getStr());
     152             : 
     153           0 :     switch (xSupp->getRememberPasswordMode())
     154             :     {
     155             :     default:
     156             :         case ucb::RememberAuthentication_NO:
     157           0 :             g_mount_operation_set_password_save(op, G_PASSWORD_SAVE_NEVER);
     158           0 :             break;
     159             :         case ucb::RememberAuthentication_SESSION:
     160           0 :             g_mount_operation_set_password_save(op, G_PASSWORD_SAVE_FOR_SESSION);
     161           0 :             break;
     162             :         case ucb::RememberAuthentication_PERSISTENT:
     163           0 :             g_mount_operation_set_password_save(op, G_PASSWORD_SAVE_PERMANENTLY);
     164           0 :             break;
     165             :     }
     166             : 
     167           0 :     if (pThis->m_pPrevPassword)
     168           0 :         free(pThis->m_pPrevPassword);
     169           0 :     pThis->m_pPrevPassword = strdup(OUStringToOString(aPassword, RTL_TEXTENCODING_UTF8).getStr());
     170           0 :     if (pThis->m_pPrevUsername)
     171           0 :         free(pThis->m_pPrevUsername);
     172           0 :     pThis->m_pPrevUsername = strdup(OUStringToOString(aUserName, RTL_TEXTENCODING_UTF8).getStr());
     173           0 :     g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
     174             : }
     175             : 
     176           0 : GMountOperation *ooo_mount_operation_new(const uno::Reference< ucb::XCommandEnvironment >& rEnv)
     177             : {
     178           0 :     OOoMountOperation *pRet = static_cast<OOoMountOperation*>(g_object_new (OOO_TYPE_MOUNT_OPERATION, NULL));
     179           0 :     pRet->pEnv = &rEnv;
     180           0 :     return &pRet->parent_instance;
     181             : }
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11