Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | Copyright (C) 2006-2013 Werner Dittmann |
| 3 | |
| 4 | This program is free software: you can redistribute it and/or modify |
| 5 | it under the terms of the GNU Lesser General Public License as published by |
| 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/ZIDRecordFile.h> |
| 22 | |
| 23 | #ifndef _ZIDCACHEFILE_H_ |
| 24 | #define _ZIDCACHEFILE_H_ |
| 25 | |
| 26 | |
| 27 | /** |
| 28 | * @file ZIDCacheFile.h |
| 29 | * @brief ZID cache management |
| 30 | * |
| 31 | * A ZID file stores (caches) some data that helps ZRTP to achives its |
| 32 | * key continuity feature. See @c ZIDRecord for further info which data |
| 33 | * the ZID file contains. |
| 34 | * |
| 35 | * @ingroup GNU_ZRTP |
| 36 | * @{ |
| 37 | */ |
| 38 | |
| 39 | /** |
| 40 | * This class implements a ZID (ZRTP Identifiers) file. |
| 41 | * |
| 42 | * The interface defintion @c ZIDCache.h contains the method documentation. |
| 43 | * The ZID cache file holds information about peers. |
| 44 | * |
| 45 | * @author: Werner Dittmann <Werner.Dittmann@t-online.de> |
| 46 | */ |
| 47 | |
| 48 | class __EXPORT ZIDCacheFile: public ZIDCache { |
| 49 | |
| 50 | private: |
| 51 | |
| 52 | FILE* zidFile; |
| 53 | unsigned char associatedZid[IDENTIFIER_LEN]; |
| 54 | |
| 55 | void createZIDFile(char* name); |
| 56 | void checkDoMigration(char* name); |
| 57 | |
| 58 | public: |
| 59 | |
| 60 | ZIDCacheFile(): zidFile(NULL) {}; |
| 61 | |
| 62 | ~ZIDCacheFile(); |
| 63 | |
| 64 | int open(char *name); |
| 65 | |
| 66 | bool isOpen() { return (zidFile != NULL); }; |
| 67 | |
| 68 | void close(); |
| 69 | |
| 70 | ZIDRecord *getRecord(unsigned char *zid); |
| 71 | |
| 72 | unsigned int saveRecord(ZIDRecord *zidRecord); |
| 73 | |
| 74 | const unsigned char* getZid() { return associatedZid; }; |
| 75 | |
| 76 | int32_t getPeerName(const uint8_t *peerZid, std::string *name); |
| 77 | |
| 78 | void putPeerName(const uint8_t *peerZid, const std::string name); |
| 79 | |
| 80 | // Not implemented for file base cache |
| 81 | void cleanup() {}; |
| 82 | }; |
| 83 | |
| 84 | /** |
| 85 | * @} |
| 86 | */ |
| 87 | #endif |