Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 2 | Copyright (C) 2006-2010 Werner Dittmann |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 3 | |
| 4 | This program is free software: you can redistribute it and/or modify |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 5 | it under the terms of the GNU General Public License as published by |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 6 | the Free Software Foundation, either version 3 of the License, or |
| 7 | (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #include <stdio.h> |
| 19 | |
| 20 | #include <libzrtpcpp/ZIDCache.h> |
| 21 | #include <libzrtpcpp/ZIDRecordDb.h> |
| 22 | #include <libzrtpcpp/zrtpCacheDbBackend.h> |
| 23 | |
| 24 | #ifndef _ZIDCACHEDB_H_ |
| 25 | #define _ZIDCACHEDB_H_ |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * @file ZIDCacheDb.h |
| 30 | * @brief ZID cache management |
| 31 | * |
| 32 | * A ZID file stores (caches) some data that helps ZRTP to achives its |
| 33 | * key continuity feature. See @c ZIDRecordDb for further info which data |
| 34 | * the ZID file contains. |
| 35 | * |
| 36 | * @ingroup GNU_ZRTP |
| 37 | * @{ |
| 38 | */ |
| 39 | |
| 40 | /** |
| 41 | * This class implements a ZID (ZRTP Identifiers) file. |
| 42 | * |
| 43 | * The interface defintion @c ZIDCache.h contains the method documentation. |
| 44 | * The ZID cache file holds information about peers. |
| 45 | * |
| 46 | * @author: Werner Dittmann <Werner.Dittmann@t-online.de> |
| 47 | */ |
| 48 | |
| 49 | class __EXPORT ZIDCacheDb: public ZIDCache { |
| 50 | |
| 51 | private: |
| 52 | |
| 53 | void *zidFile; |
| 54 | unsigned char associatedZid[IDENTIFIER_LEN]; |
| 55 | |
| 56 | dbCacheOps_t cacheOps; |
| 57 | |
| 58 | char errorBuffer[DB_CACHE_ERR_BUFF_SIZE]; |
| 59 | |
| 60 | void createZIDFile(char* name); |
| 61 | |
| 62 | public: |
| 63 | |
| 64 | ZIDCacheDb(): zidFile(NULL) { |
| 65 | getDbCacheOps(&cacheOps); |
| 66 | }; |
| 67 | |
| 68 | ~ZIDCacheDb(); |
| 69 | |
| 70 | int open(char *name); |
| 71 | |
| 72 | bool isOpen() { return (zidFile != NULL); }; |
| 73 | |
| 74 | void close(); |
| 75 | |
| 76 | ZIDRecord *getRecord(unsigned char *zid); |
| 77 | |
| 78 | unsigned int saveRecord(ZIDRecord *zidRecord); |
| 79 | |
| 80 | const unsigned char* getZid() { return associatedZid; }; |
| 81 | |
| 82 | int32_t getPeerName(const uint8_t *peerZid, std::string *name); |
| 83 | |
| 84 | void putPeerName(const uint8_t *peerZid, const std::string name); |
| 85 | |
| 86 | void cleanup(); |
| 87 | |
| 88 | }; |
| 89 | |
| 90 | /** |
| 91 | * @} |
| 92 | */ |
| 93 | #endif |