SIP Witch 1.9.15
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cache.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU 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 
26 #ifndef _SIPWITCH_CACHE_H_
27 #define _SIPWITCH_CACHE_H_
28 
29 #ifndef _UCOMMON_STRING_H_
30 #include <ucommon/string.h>
31 #endif
32 
33 #ifndef _UCOMMON_PLATFORM_H_
34 #include <ucommon/platform.h>
35 #endif
36 
37 #ifndef _UCOMMON_SOCKET_H_
38 #include <ucommon/socket.h>
39 #endif
40 
41 #ifndef __SIPWITCH_NAMESPACE_H_
42 #include <sipwitch/namespace.h>
43 #endif
44 
45 #ifndef __SIPWITCH_MAPPED_H_
46 #include <sipwitch/mapped.h>
47 #endif
48 
49 namespace sipwitch {
50 
56 class __EXPORT Cache : public LinkedObject
57 {
58 protected:
59  Cache();
60 
61  static void expire(LinkedObject **list, LinkedObject **free);
62 
63 public:
64  time_t created;
65  time_t expires;
66 };
67 
72 class __EXPORT cache : private Cache
73 {
74 public:
75  static void init(void);
76  static void cleanup(void);
77  static void userdump(void);
78 };
79 
84 class __EXPORT UserCache : public Cache
85 {
86 private:
87  void release(void);
88 
89 protected:
90  UserCache();
91 
92  static UserCache *request(const char *id);
93 
94 public:
95  char userid[32];
96  struct sockaddr_internet address;
97 
98  inline void set(struct sockaddr *addr)
99  {memcpy(&address, addr, sizeof(address));}
100 
108  static void add(const char *id, struct sockaddr *addr, time_t create, unsigned expire = 130);
109 
115  static UserCache *find(const char *id);
116 
121  static void release(UserCache *entry);
122 };
123 
124 } // namespace sipwitch
125 
126 #endif
time_t expires
Definition: cache.h:65
Definitions for memory mapped objects that may be shared between processes.
URI cache for tags, local, and remote id's.
Definition: cache.h:56
GNU SIP Witch library namespace.
Cache management functions.
Definition: cache.h:72
time_t created
Definition: cache.h:64
User caches may be used to contact nearby users in multicast registries.
Definition: cache.h:84
void set(struct sockaddr *addr)
Definition: cache.h:98