ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/account/metadata.C
Revision: 1.3
Committed: Tue Aug 28 17:08:12 2007 UTC (19 years ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.2: +25 -18 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

File Contents

# User Rev Content
1 pippijn 1.3 /**
2     * metadata.C: Metadata management
3     * Rights to this code are documented in doc/pod/gplicense.pod.
4     *
5     * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
6     */
7    
8 pippijn 1.1 #include "atheme.h"
9 pippijn 1.2 #include <account/chanacs.h>
10     #include <account/mychan.h>
11     #include <account/mymemo.h>
12     #include <account/mynick.h>
13     #include <account/myuser.h>
14     #include <account/metadata.h>
15 pippijn 1.1
16     /*******************
17     * M E T A D A T A *
18     *******************/
19    
20     has_metadata::callbacks has_metadata::callback;
21    
22     metadata *
23 pippijn 1.3 has_metadata::add_metadata (char const * const name, char const * const value)
24 pippijn 1.1 {
25     bool is_private = false;
26 pippijn 1.3 char *newname = sstrdup (name);
27     char *newvalue = sstrdup (value);
28     metadata_map::iterator it = mdmap.find (newname);
29 pippijn 1.1
30 pippijn 1.3 callback.metadata_change (this, name, value);
31 pippijn 1.2 if (it != mdmap.end ())
32 pippijn 1.1 {
33 pippijn 1.2 metadata *md = it->second;
34 pippijn 1.3 is_private = md->is_private;
35     mdmap.erase (it);
36     delete md;
37 pippijn 1.1 }
38    
39 pippijn 1.3 if (is_private || !strncmp ("private:", name, 8))
40 pippijn 1.1 is_private = true;
41    
42 pippijn 1.3 return mdmap[newname] = new metadata (newname, newvalue, is_private);
43 pippijn 1.1 }
44    
45     bool
46 pippijn 1.3 has_metadata::del_metadata (char const * const name)
47 pippijn 1.1 {
48 pippijn 1.2 metadata_map::iterator it = mdmap.find (name);
49 pippijn 1.1
50 pippijn 1.3 callback.metadata_change (this, name, NULL);
51 pippijn 1.1
52 pippijn 1.2 if (it != mdmap.end ())
53 pippijn 1.1 {
54 pippijn 1.2 mdmap.erase (it);
55     delete it->second;
56 pippijn 1.1 return true;
57     }
58    
59     return false;
60     }
61    
62     metadata *
63 pippijn 1.3 has_metadata::find_metadata (char const * const name)
64 pippijn 1.1 {
65 pippijn 1.2 metadata_map::iterator it = mdmap.find (name);
66     if (it != mdmap.end ())
67     return it->second;
68 pippijn 1.1
69     return NULL;
70     }
71    
72     void
73     has_metadata::clear_metadata (void)
74     {
75 pippijn 1.3 metadata_map::iterator it = mdmap.begin ();
76     metadata_map::iterator et = mdmap.end ();
77 pippijn 1.1
78 pippijn 1.3 while (it != et)
79 pippijn 1.1 {
80 pippijn 1.3 callback.metadata_change (this, it->second->key, NULL);
81 pippijn 1.1 delete it->second;
82 pippijn 1.3 ++it;
83 pippijn 1.1 }
84    
85     mdmap.clear ();
86     }