add logging for kimmo; refs #155
This commit is contained in:
		| @@ -5,6 +5,7 @@ | ||||
| //       1         2         3         4         5         6         7         8 | ||||
| // 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| #include <qbrowserlib/log.hxx> | ||||
| #include <QtCore/QFile> | ||||
| #include <QtCore/QDir> | ||||
| #include <QtCore/QFileInfo> | ||||
| @@ -22,7 +23,12 @@ class Storage: public QObject { | ||||
|     //! Emitted if file content has changed. | ||||
|     void changed(); | ||||
|   public: | ||||
|     Storage() {} | ||||
|     Storage() { | ||||
|       TRC; | ||||
|     } | ||||
|     ~Storage() { | ||||
|       TRC; | ||||
|     } | ||||
|     /*! @return true if readable or writable */ | ||||
|     bool valid() { | ||||
|       return readable() || writeable(); | ||||
| @@ -41,6 +47,11 @@ class Storage: public QObject { | ||||
|     virtual QStringList read() = 0; | ||||
|     //! Writes storage content from string list. | ||||
|     virtual bool write(const QStringList& out) = 0; | ||||
|   public Q_SLOTS: | ||||
|     void emitChanged() { | ||||
|       TRC; | ||||
|       changed(); | ||||
|     } | ||||
| }; | ||||
|  | ||||
| //! Implement @ref Storage for files. | ||||
| @@ -49,11 +60,12 @@ class FileStorage: public Storage { | ||||
|   public: | ||||
|     /*! @param file full path to storage file */ | ||||
|     FileStorage(QString file): _file(file) { | ||||
|       TRC; LOG<<"file: "<<file; | ||||
|       _watcher.addPath(QFileInfo(_file).absolutePath()); | ||||
|       assert(connect(&_watcher, SIGNAL(directoryChanged(const QString&)), | ||||
|                      SLOT(setupWatcher()))); | ||||
|       assert(connect(&_watcher, SIGNAL(fileChanged(const QString&)), | ||||
|                      SIGNAL(changed()))); | ||||
|                      SLOT(emitChanged()))); | ||||
|     } | ||||
|     QString name() { | ||||
|       return _file.fileName(); | ||||
| @@ -67,6 +79,7 @@ class FileStorage: public Storage { | ||||
|          QFileInfo(_file).absoluteDir().exists()); | ||||
|     } | ||||
|     QStringList read() { | ||||
|       TRC; | ||||
|       QStringList res; | ||||
|       if (readable()) { | ||||
|         if (_file.open(QIODevice::ReadOnly)) | ||||
| @@ -76,6 +89,7 @@ class FileStorage: public Storage { | ||||
|       return res; | ||||
|     } | ||||
|     bool write(const QStringList& out) { | ||||
|       TRC; | ||||
|       bool res(false); | ||||
|       if (writeable()) { | ||||
|         if (_file.open(QIODevice::WriteOnly)) | ||||
| @@ -86,13 +100,14 @@ class FileStorage: public Storage { | ||||
|     } | ||||
|   private Q_SLOTS: | ||||
|     void setupWatcher() { | ||||
|       TRC; | ||||
|       bool watching(_watcher.files().size()); | ||||
|       if (watching) // remove watchlist if already existent | ||||
|         _watcher.removePaths(_watcher.files()); | ||||
|       if (readable()) { // add file to watchlist | ||||
|         _watcher.addPath(_file.fileName()); | ||||
|         if (!watching) // send change event if file is initially created | ||||
|           changed(); | ||||
|           emitChanged(); | ||||
|       } | ||||
|     } | ||||
|   private: | ||||
|   | ||||
| @@ -250,6 +250,82 @@ class SmartCardAuth: public QObject { | ||||
|  | ||||
|   private: | ||||
|  | ||||
|     int minPinLen(const std::string& name) { | ||||
|       TRC; LOG<<name.c_str(); | ||||
|       try { | ||||
|         pcsc::Connection pcsc; | ||||
|         pcsc::Connection::Reader& reader(pcsc.reader(name)); | ||||
| #ifndef Q_OS_MAC | ||||
|         pcsc::Connection::Reader::Transaction lock(reader); | ||||
| #endif | ||||
|         // first try to read version info | ||||
|         if (reader.transmit(0x00, 0xA4, 0x08, 0x0C, "\x3f\x00\x56\x49", 4) | ||||
|             != std::string("\x90\x00", 2) || !reader) { | ||||
|           LOG<<"Select File failed"; | ||||
|           return -2; | ||||
|         } | ||||
|         std::string res(reader.transmit(0x00, 0xB0, 0x00, 0x00)); | ||||
|         if (res.substr(res.size()-2)!=std::string("\x90\x00", 2)) { | ||||
|           LOG<<"read error"; | ||||
|           return -2; | ||||
|         } | ||||
|         LOG<<"version text is: "<<res.substr(4, res[3]).c_str(); | ||||
|         // if (res.substr(4, res[3]) != "RAPost 2009" && | ||||
|         //     res.substr(4, res[3]) != "RAPost 2010") { | ||||
|         //   LOG<<"unsupported card"; | ||||
|         //   return -2; | ||||
|         // } | ||||
|         if (retCode(reader.transmit(0x00, 0xA4, 0x00, 0x0C)) == 0x9000) { | ||||
|           int value(retCode(reader.transmit(0x00, 0x20, 0x00, 0x81))); | ||||
|           if ((value&0x63C0)==0x63C0) return value&0x0F; | ||||
|         } else { | ||||
|           LOG<<"**** ERROR in select MF while reading pin status"; | ||||
|         } | ||||
|         return -1; // locked | ||||
|       } catch (const std::exception& x) { | ||||
|         LOG<<"**** ERROR while reading pin status: "<<x.what(); | ||||
|         return -2; | ||||
|       } | ||||
|     } | ||||
|      | ||||
|     int maxPinLen(const std::string& name) { | ||||
|       TRC; LOG<<name.c_str(); | ||||
|       try { | ||||
|         pcsc::Connection pcsc; | ||||
|         pcsc::Connection::Reader& reader(pcsc.reader(name)); | ||||
| #ifndef Q_OS_MAC | ||||
|         pcsc::Connection::Reader::Transaction lock(reader); | ||||
| #endif | ||||
|         // first try to read version info | ||||
|         if (reader.transmit(0x00, 0xA4, 0x08, 0x0C, "\x3f\x00\x56\x49", 4) | ||||
|             != std::string("\x90\x00", 2) || !reader) { | ||||
|           LOG<<"Select File failed"; | ||||
|           return -2; | ||||
|         } | ||||
|         std::string res(reader.transmit(0x00, 0xB0, 0x00, 0x00)); | ||||
|         if (res.substr(res.size()-2)!=std::string("\x90\x00", 2)) { | ||||
|           LOG<<"read error"; | ||||
|           return -2; | ||||
|         } | ||||
|         LOG<<"version text is: "<<res.substr(4, res[3]).c_str(); | ||||
|         // if (res.substr(4, res[3]) != "RAPost 2009" && | ||||
|         //     res.substr(4, res[3]) != "RAPost 2010") { | ||||
|         //   LOG<<"unsupported card"; | ||||
|         //   return -2; | ||||
|         // } | ||||
|         if (retCode(reader.transmit(0x00, 0xA4, 0x00, 0x0C)) == 0x9000) { | ||||
|           int value(retCode(reader.transmit(0x00, 0x20, 0x00, 0x81))); | ||||
|           if ((value&0x63C0)==0x63C0) return value&0x0F; | ||||
|         } else { | ||||
|           LOG<<"**** ERROR in select MF while reading pin status"; | ||||
|         } | ||||
|         return -1; // locked | ||||
|       } catch (const std::exception& x) { | ||||
|         LOG<<"**** ERROR while reading pin status: "<<x.what(); | ||||
|         return -2; | ||||
|       } | ||||
|     } | ||||
|      | ||||
|     int retries(const std::string& name) { | ||||
|       TRC; LOG<<name.c_str(); | ||||
|       try { | ||||
|   | ||||
| @@ -3,6 +3,10 @@ QMAKE_LIBDIR += @top_builddir@/src/qbrowserlib | ||||
| QMAKE_LIBDIR += @top_builddir@/src/qbrowserlib/release | ||||
| QMAKE_LIBS += -lqbrowserlib | ||||
|  | ||||
| macx { | ||||
|   CONFIG += x86 | ||||
| } | ||||
|  | ||||
| HEADERS = @srcdir@/filewatch.hxx | ||||
|  | ||||
| SOURCES = @srcdir@/filewatch.cxx | ||||
|   | ||||
		Reference in New Issue
	
	Block a user