Merge branch 'master' of ssh://gnunet.org/gnunet
[oweals/gnunet.git] / src / include / gnunet_friends_lib.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2013 Christian Grothoff
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @author Christian Grothoff
21  *
22  * @file
23  * Library to read and write the FRIENDS file
24  *
25  * @defgroup friends  Friends library
26  * Library to read and write the FRIENDS file
27  * @{
28  */
29 #ifndef GNUNET_FRIENDS_LIB_H
30 #define GNUNET_FRIENDS_LIB_H
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 #include "gnunet_util_lib.h"
41
42
43 /**
44  * Signature of a function called on each friend found.
45  *
46  * @param cls closure
47  * @param friend_id peer identity of the friend
48  */
49 typedef void (*GNUNET_FRIENDS_Callback)(void *cls,
50                                         const struct GNUNET_PeerIdentity *friend_id);
51
52
53 /**
54  * Parse the FRIENDS file.
55  *
56  * @param cfg our configuration
57  * @param cb function to call on each friend found
58  * @param cb_cls closure for @a cb
59  * @return #GNUNET_OK on success, #GNUNET_SYSERR on parsing errors
60  */
61 int
62 GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg,
63                       GNUNET_FRIENDS_Callback cb,
64                       void *cb_cls);
65
66
67 /**
68  * Handle for writing a friends file.
69  */
70 struct GNUNET_FRIENDS_Writer;
71
72
73 /**
74  * Start writing a fresh FRIENDS file.  Will make a backup of the
75  * old one.
76  *
77  * @param cfg configuration to use.
78  * @return NULL on error
79  */
80 struct GNUNET_FRIENDS_Writer *
81 GNUNET_FRIENDS_write_start (const struct GNUNET_CONFIGURATION_Handle *cfg);
82
83
84 /**
85  * Finish writing out the friends file.
86  *
87  * @param w write handle
88  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
89  */
90 int
91 GNUNET_FRIENDS_write_stop (struct GNUNET_FRIENDS_Writer *w);
92
93
94 /**
95  * Add a friend to the friends file.
96  *
97  * @param w write handle
98  * @param friend_id friend to add
99  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
100  */
101 int
102 GNUNET_FRIENDS_write (struct GNUNET_FRIENDS_Writer *w,
103                       const struct GNUNET_PeerIdentity *friend_id);
104
105
106 #if 0                           /* keep Emacsens' auto-indent happy */
107 {
108 #endif
109 #ifdef __cplusplus
110 }
111 #endif
112
113 #endif
114
115 /** @} */  /* end of group */