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

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 395
Merged at revision: 410
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-07
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-06
Diff against target: 520 lines (+490/-0)
5 files modified
src/plugin/folderlistmodel/CMakeLists.txt (+4/-0)
src/plugin/folderlistmodel/smb/smblocation.cpp (+84/-0)
src/plugin/folderlistmodel/smb/smblocation.h (+54/-0)
src/plugin/folderlistmodel/smb/smblocationauthentication.cpp (+249/-0)
src/plugin/folderlistmodel/smb/smblocationauthentication.h (+99/-0)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-07
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+252976@code.launchpad.net

Commit message

SmbLocation classes

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Arto Jalkanen (ajalkane) wrote :

Instead of using "static QByteArray m_AuthUser[MAX_AUTH_INSTANCES];" modern C++ prefers using unnamed namespaces, for example:

namespace {
  QByteArray m_AuthUser[MAX_AUTH_INSTANCES];
  QByteArray m_AuthPass[MAX_AUTH_INSTANCES];
  void * m_instances[MAX_AUTH_INSTANCES];
}

review: Approve
Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

OK, nice advice.

I will try to change this.

Thanks.

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

Changed smbutil.cpp and smblocationauthentication.cpp to use unamed namespace on https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-08 because it also had a pot file to revert.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
395. By Carlos Jose Mazieri

removing merge conflicts

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

With those changes, is this ready to land now?

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

Same as samba-browsing-11. I made changes Arto requested.

Carlos

On 5/19/15, Alan Pope ξƒΏ <email address hidden> wrote:
> With those changes, is this ready to land now?
> --
> https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-07/+merge/252976
> You are the owner of
> lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-07.
>

Revision history for this message
Arto Jalkanen (ajalkane) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/plugin/folderlistmodel/CMakeLists.txt'
2--- src/plugin/folderlistmodel/CMakeLists.txt 2015-04-29 22:34:32 +0000
3+++ src/plugin/folderlistmodel/CMakeLists.txt 2015-05-06 22:11:18 +0000
4@@ -69,6 +69,10 @@
5 smb/qsambaclient/src/smblocationdiriterator.h
6 smb/qsambaclient/src/smbobject.cpp
7 smb/qsambaclient/src/smbobject.h
8+ smb/smblocation.h
9+ smb/smblocation.cpp
10+ smb/smblocationauthentication.cpp
11+ smb/smblocationauthentication.h
12 net/netauthenticationdata.cpp
13 net/netauthenticationdata.h
14 net/netutil.cpp
15
16=== added file 'src/plugin/folderlistmodel/smb/smblocation.cpp'
17--- src/plugin/folderlistmodel/smb/smblocation.cpp 1970-01-01 00:00:00 +0000
18+++ src/plugin/folderlistmodel/smb/smblocation.cpp 2015-05-06 22:11:18 +0000
19@@ -0,0 +1,84 @@
20+/**************************************************************************
21+ *
22+ * Copyright 2015 Canonical Ltd.
23+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
24+ *
25+ * This program is free software; you can redistribute it and/or modify
26+ * it under the terms of the GNU Lesser General Public License as published by
27+ * the Free Software Foundation; version 3.
28+ *
29+ * This program is distributed in the hope that it will be useful,
30+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
31+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32+ * GNU Lesser General Public License for more details.
33+ *
34+ * You should have received a copy of the GNU Lesser General Public License
35+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
36+ *
37+ * File: smblocation.cpp
38+ * Date: 17/01/2015
39+ */
40+
41+#include "smblocation.h"
42+#include "smbutil.h"
43+#include "smbiteminfo.h"
44+#include "smblistworker.h"
45+#include "iorequest.h"
46+#include "ioworkerthread.h"
47+
48+SmbLocation::SmbLocation(int type, QObject *parent)
49+ : Location(type, parent)
50+ , SmbLocationAuthentication()
51+{
52+ m_smb = new SmbUtil(suitableAuthenticationFunction());
53+ setAuthentication(::qgetenv("USER"), QString());
54+}
55+
56+
57+SmbLocation::~SmbLocation()
58+{
59+
60+}
61+
62+
63+//======================================================================================================
64+/*!
65+ * \brief SmbLocation::setAuthentication() saves user/password ot be used in current SmbLocationAuthentication function
66+ *
67+ * These information will be used in further Samba authentication for this instance
68+ *
69+ * \param user
70+ * \param password
71+ */
72+void SmbLocation::setAuthentication(const QString &user,
73+ const QString &password)
74+{
75+ //setInfo is not static
76+ SmbLocationAuthentication::setInfo(user,password);
77+}
78+
79+
80+QString SmbLocation::currentAuthenticationUser()
81+{
82+ //currenAuthUser is not static
83+ return SmbLocationAuthentication::currentAuthUser();
84+}
85+
86+
87+QString SmbLocation::currentAuthenticationPassword()
88+{
89+ return SmbLocationAuthentication::currentAuthPassword();
90+}
91+
92+
93+DirItemInfo * SmbLocation::newItemInfo(const QString &urlPath)
94+{
95+ return new SmbItemInfo(urlPath, m_smb);
96+}
97+
98+
99+DirListWorker * SmbLocation::newListWorker(const QString &urlPath, QDir::Filter filter, const bool isRecursive)
100+{
101+ return new SmbListWorker(urlPath,filter,isRecursive, m_info ? m_info->isHost() : false, m_smb);
102+}
103+
104
105=== added file 'src/plugin/folderlistmodel/smb/smblocation.h'
106--- src/plugin/folderlistmodel/smb/smblocation.h 1970-01-01 00:00:00 +0000
107+++ src/plugin/folderlistmodel/smb/smblocation.h 2015-05-06 22:11:18 +0000
108@@ -0,0 +1,54 @@
109+/**************************************************************************
110+ *
111+ * Copyright 2015 Canonical Ltd.
112+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
113+ *
114+ * This program is free software; you can redistribute it and/or modify
115+ * it under the terms of the GNU Lesser General Public License as published by
116+ * the Free Software Foundation; version 3.
117+ *
118+ * This program is distributed in the hope that it will be useful,
119+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
120+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
121+ * GNU Lesser General Public License for more details.
122+ *
123+ * You should have received a copy of the GNU Lesser General Public License
124+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
125+ *
126+ * File: smblocation.h
127+ * Date: 17/01/2015
128+ */
129+
130+#ifndef SMBLOCATION_H
131+#define SMBLOCATION_H
132+
133+#include "location.h"
134+#include "smblocationauthentication.h"
135+#include "smbobject.h"
136+
137+
138+class SmbLocation : public Location, public SmbLocationAuthentication
139+{
140+ Q_OBJECT
141+public:
142+ explicit SmbLocation(int type, QObject *parent=0);
143+ ~SmbLocation();
144+
145+public:
146+ virtual DirItemInfo * newItemInfo(const QString& urlPath);
147+ virtual DirListWorker * newListWorker(const QString &urlPath,
148+ QDir::Filter filter,
149+ const bool isRecursive);
150+ virtual QString currentAuthenticationUser();
151+ virtual QString currentAuthenticationPassword();
152+
153+public slots:
154+ virtual void setAuthentication(const QString& user,
155+ const QString& password);
156+
157+
158+private:
159+ SmbUtil_Ptr m_smb;
160+};
161+
162+#endif // SMBLOCATION_H
163
164=== added file 'src/plugin/folderlistmodel/smb/smblocationauthentication.cpp'
165--- src/plugin/folderlistmodel/smb/smblocationauthentication.cpp 1970-01-01 00:00:00 +0000
166+++ src/plugin/folderlistmodel/smb/smblocationauthentication.cpp 2015-05-06 22:11:18 +0000
167@@ -0,0 +1,249 @@
168+/**************************************************************************
169+ *
170+ * Copyright 2015 Canonical Ltd.
171+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
172+ *
173+ * This program is free software; you can redistribute it and/or modify
174+ * it under the terms of the GNU Lesser General Public License as published by
175+ * the Free Software Foundation; version 3.
176+ *
177+ * This program is distributed in the hope that it will be useful,
178+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
179+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
180+ * GNU Lesser General Public License for more details.
181+ *
182+ * You should have received a copy of the GNU Lesser General Public License
183+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
184+ *
185+ * File: smblocationauthentication.cpp
186+ * Date: 17/01/2015
187+ */
188+
189+#include "smblocationauthentication.h"
190+#include <QDebug>
191+
192+#define GOOD_INDEX() (m_infoIndex >= 0 && m_infoIndex < MAX_AUTH_INSTANCES)
193+
194+#if defined(REGRESSION_TEST_FOLDERLISTMODEL) && defined(SIMPLE_UI)
195+# define DEBUG_AUTHENTICATION() qDebug() << Q_FUNC_INFO << user << passwd
196+#else
197+# define DEBUG_AUTHENTICATION() /**/
198+#endif
199+
200+
201+static QByteArray m_AuthUser[MAX_AUTH_INSTANCES];
202+static QByteArray m_AuthPass[MAX_AUTH_INSTANCES];
203+static void * m_instances[MAX_AUTH_INSTANCES];
204+
205+SmbLocationAuthentication::SmbLocationAuthentication() : m_infoIndex(-1)
206+{
207+ for(int counter = 0; counter < MAX_AUTH_INSTANCES; ++counter)
208+ {
209+ if (m_instances[counter] == 0)
210+ {
211+ m_infoIndex = counter;
212+ m_instances[m_infoIndex] = this;
213+ break;
214+ }
215+ }
216+}
217+
218+//============================================================================
219+/*!
220+ * \brief SmbLocationAuthentication::~SmbLocationAuthentication
221+ */
222+SmbLocationAuthentication::~SmbLocationAuthentication()
223+{
224+ if (GOOD_INDEX())
225+ {
226+ m_instances[m_infoIndex] = 0;
227+ }
228+ else
229+ {
230+ qDebug() << Q_FUNC_INFO << "ERROR no m_instances[] index";
231+ }
232+}
233+
234+//============================================================================
235+/*!
236+ * \brief SmbLocationAuthentication::setInfo
237+ * \param user
238+ * \param password
239+ */
240+void SmbLocationAuthentication::setInfo(const QString &user, const QString &password)
241+{
242+ if (GOOD_INDEX())
243+ {
244+ m_AuthUser[m_infoIndex] = user.toLocal8Bit();
245+ m_AuthPass[m_infoIndex] = password.toLocal8Bit();
246+ }
247+ else
248+ {
249+ qDebug() << Q_FUNC_INFO << "ERROR no m_instances[] index";
250+ }
251+}
252+
253+//============================================================================
254+/*!
255+ * \brief SmbLocationAuthentication::suitableAuthenticationFunction
256+ * \return
257+ */
258+Smb::AuthenticationFunction
259+SmbLocationAuthentication::suitableAuthenticationFunction() const
260+{
261+ switch(m_infoIndex)
262+ {
263+ case 0: return &SmbLocationAuthentication::authenticateCallBack0;
264+ case 1: return &SmbLocationAuthentication::authenticateCallBack1;
265+ case 2: return &SmbLocationAuthentication::authenticateCallBack2;
266+ case 3: return &SmbLocationAuthentication::authenticateCallBack3;
267+ default: return 0;
268+ }
269+}
270+
271+//============================================================================
272+/*!
273+ * \brief SmbLocationAuthentication::authenticateCallBack0
274+ * \param server
275+ * \param share
276+ * \param wrkgrp
277+ * \param wrkgrplen
278+ * \param user
279+ * \param userlen
280+ * \param passwd
281+ * \param passwdlen
282+ */
283+void SmbLocationAuthentication::authenticateCallBack0(const char *server,
284+ const char *share,
285+ char *wrkgrp,
286+ int wrkgrplen,
287+ char *user,
288+ int userlen,
289+ char *passwd,
290+ int passwdlen)
291+{
292+ Q_UNUSED(server);
293+ Q_UNUSED(share);
294+ Q_UNUSED(wrkgrp);
295+ Q_UNUSED(wrkgrplen);
296+
297+ ::strncpy(user, m_AuthUser[0].constData(), --userlen);
298+ ::strncpy(passwd, m_AuthPass[0].constData(), --passwdlen);
299+ DEBUG_AUTHENTICATION();
300+}
301+
302+//============================================================================
303+/*!
304+ * \brief SmbLocationAuthentication::authenticateCallBack1
305+ * \param server
306+ * \param share
307+ * \param wrkgrp
308+ * \param wrkgrplen
309+ * \param user
310+ * \param userlen
311+ * \param passwd
312+ * \param passwdlen
313+ */
314+void SmbLocationAuthentication::authenticateCallBack1(const char *server,
315+ const char *share,
316+ char *wrkgrp,
317+ int wrkgrplen,
318+ char *user,
319+ int userlen,
320+ char *passwd,
321+ int passwdlen)
322+{
323+ Q_UNUSED(server);
324+ Q_UNUSED(share);
325+ Q_UNUSED(wrkgrp);
326+ Q_UNUSED(wrkgrplen);
327+
328+ ::strncpy(user, m_AuthUser[1].constData(), --userlen);
329+ ::strncpy(passwd, m_AuthPass[1].constData(), --passwdlen);
330+ DEBUG_AUTHENTICATION();
331+}
332+
333+//============================================================================
334+/*!
335+ * \brief SmbLocationAuthentication::authenticateCallBack2
336+ * \param server
337+ * \param share
338+ * \param wrkgrp
339+ * \param wrkgrplen
340+ * \param user
341+ * \param userlen
342+ * \param passwd
343+ * \param passwdlen
344+ */
345+void SmbLocationAuthentication::authenticateCallBack2(const char *server,
346+ const char *share,
347+ char *wrkgrp,
348+ int wrkgrplen,
349+ char *user,
350+ int userlen,
351+ char *passwd,
352+ int passwdlen)
353+{
354+ Q_UNUSED(server);
355+ Q_UNUSED(share);
356+ Q_UNUSED(wrkgrp);
357+ Q_UNUSED(wrkgrplen);
358+
359+ ::strncpy(user, m_AuthUser[2].constData(), --userlen);
360+ ::strncpy(passwd, m_AuthPass[2].constData(), --passwdlen);
361+ DEBUG_AUTHENTICATION();
362+}
363+
364+//============================================================================
365+/*!
366+ * \brief SmbLocationAuthentication::authenticateCallBack3
367+ * \param server
368+ * \param share
369+ * \param wrkgrp
370+ * \param wrkgrplen
371+ * \param user
372+ * \param userlen
373+ * \param passwd
374+ * \param passwdlen
375+ */
376+void SmbLocationAuthentication::authenticateCallBack3(const char *server,
377+ const char *share,
378+ char *wrkgrp,
379+ int wrkgrplen,
380+ char *user,
381+ int userlen,
382+ char *passwd,
383+ int passwdlen)
384+{
385+ Q_UNUSED(server);
386+ Q_UNUSED(share);
387+ Q_UNUSED(wrkgrp);
388+ Q_UNUSED(wrkgrplen);
389+
390+ ::strncpy(user, m_AuthUser[3].constData(), --userlen);
391+ ::strncpy(passwd, m_AuthPass[3].constData(), --passwdlen);
392+ DEBUG_AUTHENTICATION();
393+}
394+
395+
396+QString SmbLocationAuthentication::currentAuthUser() const
397+{
398+ QString ret;
399+ if (GOOD_INDEX())
400+ {
401+ ret = m_AuthUser[m_infoIndex];
402+ }
403+ return ret;
404+}
405+
406+
407+
408+QString SmbLocationAuthentication::currentAuthPassword() const
409+{
410+ QString ret;
411+ if (GOOD_INDEX())
412+ {
413+ ret = m_AuthPass[m_infoIndex];
414+ }
415+ return ret;
416+}
417
418=== added file 'src/plugin/folderlistmodel/smb/smblocationauthentication.h'
419--- src/plugin/folderlistmodel/smb/smblocationauthentication.h 1970-01-01 00:00:00 +0000
420+++ src/plugin/folderlistmodel/smb/smblocationauthentication.h 2015-05-06 22:11:18 +0000
421@@ -0,0 +1,99 @@
422+/**************************************************************************
423+ *
424+ * Copyright 2015 Canonical Ltd.
425+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
426+ *
427+ * This program is free software; you can redistribute it and/or modify
428+ * it under the terms of the GNU Lesser General Public License as published by
429+ * the Free Software Foundation; version 3.
430+ *
431+ * This program is distributed in the hope that it will be useful,
432+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
433+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
434+ * GNU Lesser General Public License for more details.
435+ *
436+ * You should have received a copy of the GNU Lesser General Public License
437+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
438+ *
439+ * File: smblocationauthentication.h
440+ * Date: 17/01/2015
441+ */
442+
443+#ifndef SMBLOCATIONAUTHENTICATION_H
444+#define SMBLOCATIONAUTHENTICATION_H
445+
446+#include "smbutil.h"
447+
448+/*!
449+ As the function to do the Samba authentication needs to be a static function
450+ it is necessary to have many static functions to allow many instances of SmbLocation
451+ (one SmbLocation instance matches a FileManager window) browsing for example the
452+ same samba URL using different users.
453+ */
454+#define MAX_AUTH_INSTANCES 4
455+
456+
457+/*!
458+ * \brief The SmbLocationAuthentication class provides authentication Samba Authentication functions
459+ *
460+ * It intends to provide a set of functions and information (user/password) to have different instances of
461+ * objects doing samba authentication at same time
462+ */
463+class SmbLocationAuthentication
464+{
465+public:
466+ SmbLocationAuthentication();
467+ ~SmbLocationAuthentication();
468+
469+ Smb::AuthenticationFunction suitableAuthenticationFunction() const;
470+
471+ void setInfo(const QString& user,
472+ const QString& password);
473+ QString currentAuthUser() const;
474+ QString currentAuthPassword() const;
475+
476+ static void authenticateCallBack0(
477+ const char *server,
478+ const char *share,
479+ char *wrkgrp,
480+ int wrkgrplen,
481+ char *user,
482+ int userlen,
483+ char *passwd,
484+ int passwdlen);
485+
486+ static void authenticateCallBack1(
487+ const char *server,
488+ const char *share,
489+ char *wrkgrp,
490+ int wrkgrplen,
491+ char *user,
492+ int userlen,
493+ char *passwd,
494+ int passwdlen);
495+
496+ static void authenticateCallBack2(
497+ const char *server,
498+ const char *share,
499+ char *wrkgrp,
500+ int wrkgrplen,
501+ char *user,
502+ int userlen,
503+ char *passwd,
504+ int passwdlen);
505+
506+ static void authenticateCallBack3(
507+ const char *server,
508+ const char *share,
509+ char *wrkgrp,
510+ int wrkgrplen,
511+ char *user,
512+ int userlen,
513+ char *passwd,
514+ int passwdlen);
515+
516+private:
517+ int m_infoIndex;
518+};
519+
520+#endif // SMBLOCATIONAUTHENTICATION_H

Subscribers

People subscribed via source and target branches