Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/launcher/transferserver.cpp | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index 9d18b7b..a20df2f 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp | |||
@@ -16,29 +16,33 @@ | |||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #define _XOPEN_SOURCE | 20 | #define _XOPEN_SOURCE |
21 | #include <pwd.h> | 21 | #include <pwd.h> |
22 | #include <sys/types.h> | 22 | #include <sys/types.h> |
23 | #include <unistd.h> | 23 | #include <unistd.h> |
24 | #include <stdlib.h> | 24 | #include <stdlib.h> |
25 | #include <time.h> | 25 | #include <time.h> |
26 | #include <shadow.h> | 26 | #include <shadow.h> |
27 | 27 | ||
28 | #ifndef _OS_LINUX_ | ||
29 | |||
28 | extern "C" { | 30 | extern "C" { |
29 | #include <uuid/uuid.h> | 31 | #include <uuid/uuid.h> |
30 | #define UUID_H_INCLUDED | 32 | #define UUID_H_INCLUDED |
31 | } | 33 | } |
32 | 34 | ||
35 | #endif // not defined linux | ||
36 | |||
33 | #if defined(_OS_LINUX_) | 37 | #if defined(_OS_LINUX_) |
34 | #include <shadow.h> | 38 | #include <shadow.h> |
35 | #endif | 39 | #endif |
36 | 40 | ||
37 | #include <qdir.h> | 41 | #include <qdir.h> |
38 | #include <qfile.h> | 42 | #include <qfile.h> |
39 | #include <qtextstream.h> | 43 | #include <qtextstream.h> |
40 | #include <qdatastream.h> | 44 | #include <qdatastream.h> |
41 | #include <qmessagebox.h> | 45 | #include <qmessagebox.h> |
42 | #include <qstringlist.h> | 46 | #include <qstringlist.h> |
43 | #include <qfileinfo.h> | 47 | #include <qfileinfo.h> |
44 | #include <qregexp.h> | 48 | #include <qregexp.h> |
@@ -67,33 +71,64 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent , | |||
67 | } | 71 | } |
68 | 72 | ||
69 | TransferServer::~TransferServer() | 73 | TransferServer::~TransferServer() |
70 | { | 74 | { |
71 | 75 | ||
72 | } | 76 | } |
73 | 77 | ||
74 | void TransferServer::newConnection( int socket ) | 78 | void TransferServer::newConnection( int socket ) |
75 | { | 79 | { |
76 | (void) new ServerPI( socket, this ); | 80 | (void) new ServerPI( socket, this ); |
77 | } | 81 | } |
78 | 82 | ||
83 | /* | ||
84 | * small class in anonymous namespace | ||
85 | * to generate a QUUid for us | ||
86 | */ | ||
87 | namespace { | ||
88 | struct UidGen { | ||
89 | QString uuid(); | ||
90 | }; | ||
91 | #if defined(_OS_LINUX_) | ||
92 | /* | ||
93 | * linux got a /proc/sys/kernel/random/uuid file | ||
94 | * it'll generate the uuids for us | ||
95 | */ | ||
96 | QString UidGen::uuid() { | ||
97 | QFile file( "/proc/sys/kernel/random/uuid" ); | ||
98 | if (!file.open(IO_ReadOnly ) ) | ||
99 | return QString::null; | ||
100 | |||
101 | QTextStream stream(&file); | ||
102 | |||
103 | return "{" + stream.read().stripWhiteSpace() + "}"; | ||
104 | } | ||
105 | #else | ||
106 | QString UidGen::uuid() { | ||
107 | uuid_t uuid; | ||
108 | uuid_generate( uuid ); | ||
109 | return QUUid( uuid ).toString(); | ||
110 | } | ||
111 | #endif | ||
112 | } | ||
113 | |||
79 | QString SyncAuthentication::serverId() | 114 | QString SyncAuthentication::serverId() |
80 | { | 115 | { |
81 | Config cfg("Security"); | 116 | Config cfg("Security"); |
82 | cfg.setGroup("Sync"); | 117 | cfg.setGroup("Sync"); |
83 | QString r=cfg.readEntry("serverid"); | 118 | QString r=cfg.readEntry("serverid"); |
84 | if ( r.isEmpty() ) { | 119 | if ( r.isEmpty() ) { |
85 | uuid_t uuid; | 120 | UidGen gen; |
86 | uuid_generate( uuid ); | 121 | r = gen.uuid(); |
87 | cfg.writeEntry("serverid",(r = QUuid( uuid ).toString())); | 122 | cfg.writeEntry("serverid", r ); |
88 | } | 123 | } |
89 | return r; | 124 | return r; |
90 | } | 125 | } |
91 | 126 | ||
92 | QString SyncAuthentication::ownerName() | 127 | QString SyncAuthentication::ownerName() |
93 | { | 128 | { |
94 | QString vfilename = Global::applicationFileName("addressbook", | 129 | QString vfilename = Global::applicationFileName("addressbook", |
95 | "businesscard.vcf"); | 130 | "businesscard.vcf"); |
96 | if (QFile::exists(vfilename)) { | 131 | if (QFile::exists(vfilename)) { |
97 | Contact c; | 132 | Contact c; |
98 | c = Contact::readVCard( vfilename )[0]; | 133 | c = Contact::readVCard( vfilename )[0]; |
99 | return c.fullName(); | 134 | return c.fullName(); |