← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-07 into lp:ubuntu-filemanager-app

 

Carlos Jose Mazieri has proposed merging lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-07 into lp:ubuntu-filemanager-app with lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-06 as a prerequisite.

Commit message:
SmbLocation classes

Requested reviews:
  Ubuntu File Manager Developers (ubuntu-filemanager-dev)

For more details, see:
https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-07/+merge/252976

Introduces classes:
   * SmbLocation which represents Samba browsing at all
   * SmbLocationAuthentication which keeps static functions and data to authenticate against Samba, 
     it allows different instances browsing same share/folder using different users/passwords.
-- 
Your team Ubuntu File Manager Developers is requested to review the proposed merge of lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-07 into lp:ubuntu-filemanager-app.
=== modified file 'src/plugin/folderlistmodel/CMakeLists.txt'
--- src/plugin/folderlistmodel/CMakeLists.txt	2015-03-14 18:22:41 +0000
+++ src/plugin/folderlistmodel/CMakeLists.txt	2015-03-14 18:22:41 +0000
@@ -58,7 +58,11 @@
     trash/trashiteminfo.cpp
     trash/trashiteminfo.h
     trash/trashlocation.cpp
-    trash/trashlocation.h 
+    trash/trashlocation.h       
+    smb/smblocation.h
+    smb/smblocation.cpp
+    smb/smblocationauthentication.cpp
+    smb/smblocationauthentication.h
     smb/smblistworker.cpp
     smb/smblistworker.h
     smb/qsambaclient/src/smbutil.cpp
@@ -70,7 +74,7 @@
     smb/qsambaclient/src/smbobject.cpp
     smb/qsambaclient/src/smbobject.h
     net/netauthenticationdata.cpp
-    net/netauthenticationdata.h  
+    net/netauthenticationdata.h
     net/netutil.cpp
     net/netutil.h
 )

=== added file 'src/plugin/folderlistmodel/smb/smblocation.cpp'
--- src/plugin/folderlistmodel/smb/smblocation.cpp	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.cpp	2015-03-14 18:22:41 +0000
@@ -0,0 +1,84 @@
+/**************************************************************************
+ *
+ * Copyright 2015 Canonical Ltd.
+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File: smblocation.cpp
+ * Date: 17/01/2015
+ */
+
+#include "smblocation.h"
+#include "smbutil.h"
+#include "smbiteminfo.h"
+#include "smblistworker.h"
+#include "iorequest.h"
+#include "ioworkerthread.h"
+
+SmbLocation::SmbLocation(int type, QObject *parent)
+     : Location(type, parent)
+     , SmbLocationAuthentication()
+{
+     m_smb = new SmbUtil(suitableAuthenticationFunction());
+     setAuthentication(::qgetenv("USER"), QString());
+}
+
+
+SmbLocation::~SmbLocation()
+{
+
+}
+
+
+//======================================================================================================
+/*!
+ * \brief SmbLocation::setAuthentication() saves user/password ot be used in current SmbLocationAuthentication function
+ *
+ *  These information will be used in further Samba authentication for this instance
+ *
+ * \param user
+ * \param password
+ */
+void SmbLocation::setAuthentication(const QString &user,
+                                    const QString &password)
+{
+    //setInfo is not static
+    SmbLocationAuthentication::setInfo(user,password);
+}
+
+
+QString SmbLocation::currentAuthenticationUser()
+{
+    //currenAuthUser is not static
+    return SmbLocationAuthentication::currentAuthUser();
+}
+
+
+QString SmbLocation::currentAuthenticationPassword()
+{
+    return SmbLocationAuthentication::currentAuthPassword();
+}
+
+
+DirItemInfo * SmbLocation::newItemInfo(const QString &urlPath)
+{
+    return new SmbItemInfo(urlPath, m_smb);
+}
+
+
+DirListWorker * SmbLocation::newListWorker(const QString &urlPath, QDir::Filter filter, const bool isRecursive)
+{
+    return new SmbListWorker(urlPath,filter,isRecursive, m_info ? m_info->isHost() : false, m_smb);
+}
+

=== added file 'src/plugin/folderlistmodel/smb/smblocation.h'
--- src/plugin/folderlistmodel/smb/smblocation.h	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.h	2015-03-14 18:22:41 +0000
@@ -0,0 +1,54 @@
+/**************************************************************************
+ *
+ * Copyright 2015 Canonical Ltd.
+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File: smblocation.h
+ * Date: 17/01/2015
+ */
+
+#ifndef SMBLOCATION_H
+#define SMBLOCATION_H
+
+#include "location.h"
+#include "smblocationauthentication.h"
+#include "smbobject.h"
+
+
+class SmbLocation : public Location, public SmbLocationAuthentication
+{
+    Q_OBJECT
+public:
+    explicit SmbLocation(int type, QObject *parent=0);
+    ~SmbLocation();
+
+public:   
+    virtual DirItemInfo * newItemInfo(const QString& urlPath);
+    virtual DirListWorker * newListWorker(const QString &urlPath,
+                                          QDir::Filter filter,
+                                          const bool isRecursive);
+    virtual QString     currentAuthenticationUser();
+    virtual QString     currentAuthenticationPassword();
+
+public slots:   
+    virtual void setAuthentication(const QString& user,
+                                   const QString& password);
+
+
+private:
+   SmbUtil_Ptr m_smb;
+};
+
+#endif // SMBLOCATION_H

=== added file 'src/plugin/folderlistmodel/smb/smblocationauthentication.cpp'
--- src/plugin/folderlistmodel/smb/smblocationauthentication.cpp	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/smblocationauthentication.cpp	2015-03-14 18:22:41 +0000
@@ -0,0 +1,249 @@
+/**************************************************************************
+ *
+ * Copyright 2015 Canonical Ltd.
+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File: smblocationauthentication.cpp
+ * Date: 17/01/2015
+ */
+
+#include "smblocationauthentication.h"
+#include <QDebug>
+
+#define  GOOD_INDEX()  (m_infoIndex >= 0 && m_infoIndex < MAX_AUTH_INSTANCES)
+
+#if defined(REGRESSION_TEST_FOLDERLISTMODEL) && defined(SIMPLE_UI)
+# define DEBUG_AUTHENTICATION()  qDebug() << Q_FUNC_INFO << user << passwd
+#else
+# define DEBUG_AUTHENTICATION() /**/
+#endif
+
+
+static    QByteArray  m_AuthUser[MAX_AUTH_INSTANCES];
+static    QByteArray  m_AuthPass[MAX_AUTH_INSTANCES];
+static    void *      m_instances[MAX_AUTH_INSTANCES];
+
+SmbLocationAuthentication::SmbLocationAuthentication() : m_infoIndex(-1)
+{
+    for(int counter = 0; counter < MAX_AUTH_INSTANCES; ++counter)
+    {
+        if (m_instances[counter] == 0)
+        {
+            m_infoIndex = counter;
+            m_instances[m_infoIndex] = this;
+            break;
+        }
+    }
+}
+
+//============================================================================
+/*!
+ * \brief SmbLocationAuthentication::~SmbLocationAuthentication
+ */
+SmbLocationAuthentication::~SmbLocationAuthentication()
+{
+    if (GOOD_INDEX())
+    {
+        m_instances[m_infoIndex] = 0;
+    }
+    else
+    {
+        qDebug() << Q_FUNC_INFO << "ERROR no m_instances[] index";
+    }
+}
+
+//============================================================================
+/*!
+ * \brief SmbLocationAuthentication::setInfo
+ * \param user
+ * \param password
+ */
+void SmbLocationAuthentication::setInfo(const QString &user, const QString &password)
+{
+    if (GOOD_INDEX())
+    {
+        m_AuthUser[m_infoIndex] = user.toLocal8Bit();
+        m_AuthPass[m_infoIndex] = password.toLocal8Bit();
+    }
+    else
+    {
+        qDebug() << Q_FUNC_INFO << "ERROR no m_instances[] index";
+    }
+}
+
+//============================================================================
+/*!
+ * \brief SmbLocationAuthentication::suitableAuthenticationFunction
+ * \return
+ */
+Smb::AuthenticationFunction
+SmbLocationAuthentication::suitableAuthenticationFunction() const
+{
+    switch(m_infoIndex)
+    {
+       case 0:  return  &SmbLocationAuthentication::authenticateCallBack0;
+       case 1:  return  &SmbLocationAuthentication::authenticateCallBack1;
+       case 2:  return  &SmbLocationAuthentication::authenticateCallBack2;
+       case 3:  return  &SmbLocationAuthentication::authenticateCallBack3;
+       default: return  0;
+    }
+}
+
+//============================================================================
+/*!
+ * \brief SmbLocationAuthentication::authenticateCallBack0
+ * \param server
+ * \param share
+ * \param wrkgrp
+ * \param wrkgrplen
+ * \param user
+ * \param userlen
+ * \param passwd
+ * \param passwdlen
+ */
+void SmbLocationAuthentication::authenticateCallBack0(const char *server,
+                                                      const char *share,
+                                                      char *wrkgrp,
+                                                      int wrkgrplen,
+                                                      char *user,
+                                                      int userlen,
+                                                      char *passwd,
+                                                      int passwdlen)
+{
+    Q_UNUSED(server);
+    Q_UNUSED(share);
+    Q_UNUSED(wrkgrp);
+    Q_UNUSED(wrkgrplen);
+
+    ::strncpy(user,   m_AuthUser[0].constData(),  --userlen);
+    ::strncpy(passwd, m_AuthPass[0].constData(),  --passwdlen);
+    DEBUG_AUTHENTICATION();
+}
+
+//============================================================================
+/*!
+ * \brief SmbLocationAuthentication::authenticateCallBack1
+ * \param server
+ * \param share
+ * \param wrkgrp
+ * \param wrkgrplen
+ * \param user
+ * \param userlen
+ * \param passwd
+ * \param passwdlen
+ */
+void SmbLocationAuthentication::authenticateCallBack1(const char *server,
+                                                      const char *share,
+                                                      char *wrkgrp,
+                                                      int wrkgrplen,
+                                                      char *user,
+                                                      int userlen,
+                                                      char *passwd,
+                                                      int passwdlen)
+{
+    Q_UNUSED(server);
+    Q_UNUSED(share);
+    Q_UNUSED(wrkgrp);
+    Q_UNUSED(wrkgrplen);
+
+    ::strncpy(user,   m_AuthUser[1].constData(),  --userlen);
+    ::strncpy(passwd, m_AuthPass[1].constData(),  --passwdlen);
+    DEBUG_AUTHENTICATION();
+}
+
+//============================================================================
+/*!
+ * \brief SmbLocationAuthentication::authenticateCallBack2
+ * \param server
+ * \param share
+ * \param wrkgrp
+ * \param wrkgrplen
+ * \param user
+ * \param userlen
+ * \param passwd
+ * \param passwdlen
+ */
+void SmbLocationAuthentication::authenticateCallBack2(const char *server,
+                                                      const char *share,
+                                                      char *wrkgrp,
+                                                      int wrkgrplen,
+                                                      char *user,
+                                                      int userlen,
+                                                      char *passwd,
+                                                      int passwdlen)
+{
+    Q_UNUSED(server);
+    Q_UNUSED(share);
+    Q_UNUSED(wrkgrp);
+    Q_UNUSED(wrkgrplen);
+
+    ::strncpy(user,   m_AuthUser[2].constData(),  --userlen);
+    ::strncpy(passwd, m_AuthPass[2].constData(),  --passwdlen);
+    DEBUG_AUTHENTICATION();
+}
+
+//============================================================================
+/*!
+ * \brief SmbLocationAuthentication::authenticateCallBack3
+ * \param server
+ * \param share
+ * \param wrkgrp
+ * \param wrkgrplen
+ * \param user
+ * \param userlen
+ * \param passwd
+ * \param passwdlen
+ */
+void SmbLocationAuthentication::authenticateCallBack3(const char *server,
+                                                      const char *share,
+                                                      char *wrkgrp,
+                                                      int wrkgrplen,
+                                                      char *user,
+                                                      int userlen,
+                                                      char *passwd,
+                                                      int passwdlen)
+{
+    Q_UNUSED(server);
+    Q_UNUSED(share);
+    Q_UNUSED(wrkgrp);
+    Q_UNUSED(wrkgrplen);
+
+    ::strncpy(user,   m_AuthUser[3].constData(),  --userlen);
+    ::strncpy(passwd, m_AuthPass[3].constData(),  --passwdlen);
+    DEBUG_AUTHENTICATION();
+}
+
+
+QString SmbLocationAuthentication::currentAuthUser() const
+{
+    QString ret;
+    if (GOOD_INDEX())
+    {
+       ret = m_AuthUser[m_infoIndex];
+    }
+    return ret;
+}
+
+
+
+QString SmbLocationAuthentication::currentAuthPassword() const
+{
+    QString ret;
+    if (GOOD_INDEX())
+    {
+       ret = m_AuthPass[m_infoIndex];
+    }
+    return ret;
+}

=== added file 'src/plugin/folderlistmodel/smb/smblocationauthentication.h'
--- src/plugin/folderlistmodel/smb/smblocationauthentication.h	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/smblocationauthentication.h	2015-03-14 18:22:41 +0000
@@ -0,0 +1,99 @@
+/**************************************************************************
+ *
+ * Copyright 2015 Canonical Ltd.
+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File: smblocationauthentication.h
+ * Date: 17/01/2015
+ */
+
+#ifndef SMBLOCATIONAUTHENTICATION_H
+#define SMBLOCATIONAUTHENTICATION_H
+
+#include "smbutil.h"
+
+/*!
+    As the function to do the Samba authentication needs to be a static function
+    it is necessary to have many static functions to allow many instances of SmbLocation
+    (one SmbLocation instance matches a FileManager window) browsing for example the
+    same samba URL using different users.
+ */
+#define MAX_AUTH_INSTANCES   4
+
+
+/*!
+ * \brief The SmbLocationAuthentication class provides authentication Samba Authentication functions
+ *
+ *  It intends to provide a set of functions and information (user/password) to have different instances of
+ *  objects doing samba authentication at same time
+ */
+class SmbLocationAuthentication
+{
+public:
+    SmbLocationAuthentication();
+   ~SmbLocationAuthentication();
+
+    Smb::AuthenticationFunction suitableAuthenticationFunction() const;
+
+    void            setInfo(const QString& user,
+                            const QString& password);
+    QString         currentAuthUser() const;
+    QString         currentAuthPassword() const;
+
+    static void     authenticateCallBack0(
+                                const char  *server,
+                                const char  *share,
+                                char        *wrkgrp,
+                                int         wrkgrplen,
+                                char        *user,
+                                int         userlen,
+                                char        *passwd,
+                                int         passwdlen);
+
+    static void     authenticateCallBack1(
+                                const char  *server,
+                                const char  *share,
+                                char        *wrkgrp,
+                                int         wrkgrplen,
+                                char        *user,
+                                int         userlen,
+                                char        *passwd,
+                                int         passwdlen);
+
+    static void     authenticateCallBack2(
+                                const char  *server,
+                                const char  *share,
+                                char        *wrkgrp,
+                                int         wrkgrplen,
+                                char        *user,
+                                int         userlen,
+                                char        *passwd,
+                                int         passwdlen);
+
+    static void     authenticateCallBack3(
+                                const char  *server,
+                                const char  *share,
+                                char        *wrkgrp,
+                                int         wrkgrplen,
+                                char        *user,
+                                int         userlen,
+                                char        *passwd,
+                                int         passwdlen);
+
+private:
+    int  m_infoIndex;
+};
+
+#endif // SMBLOCATIONAUTHENTICATION_H


Follow ups