error handling
[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      SPDX-License-Identifier: AGPL3.0-or-later
19  */
20
21 /**
22  * @author Christian Grothoff
23  *
24  * @file
25  * Library to read and write the FRIENDS file
26  *
27  * @defgroup friends  Friends library
28  * Library to read and write the FRIENDS file
29  * @{
30  */
31 #ifndef GNUNET_FRIENDS_LIB_H
32 #define GNUNET_FRIENDS_LIB_H
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0                           /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41
42 #include "gnunet_util_lib.h"
43
44
45 /**
46  * Signature of a function called on each friend found.
47  *
48  * @param cls closure
49  * @param friend_id peer identity of the friend
50  */
51 typedef void (*GNUNET_FRIENDS_Callback)(void *cls,
52                                         const struct
53                                         GNUNET_PeerIdentity *friend_id);
54
55
56 /**
57  * Parse the FRIENDS file.
58  *
59  * @param cfg our configuration
60  * @param cb function to call on each friend found
61  * @param cb_cls closure for @a cb
62  * @return #GNUNET_OK on success, #GNUNET_SYSERR on parsing errors
63  */
64 int
65 GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg,
66                       GNUNET_FRIENDS_Callback cb,
67                       void *cb_cls);
68
69
70 /**
71  * Handle for writing a friends file.
72  */
73 struct GNUNET_FRIENDS_Writer;
74
75
76 /**
77  * Start writing a fresh FRIENDS file.  Will make a backup of the
78  * old one.
79  *
80  * @param cfg configuration to use.
81  * @return NULL on error
82  */
83 struct GNUNET_FRIENDS_Writer *
84 GNUNET_FRIENDS_write_start (const struct GNUNET_CONFIGURATION_Handle *cfg);
85
86
87 /**
88  * Finish writing out the friends file.
89  *
90  * @param w write handle
91  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
92  */
93 int
94 GNUNET_FRIENDS_write_stop (struct GNUNET_FRIENDS_Writer *w);
95
96
97 /**
98  * Add a friend to the friends file.
99  *
100  * @param w write handle
101  * @param friend_id friend to add
102  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
103  */
104 int
105 GNUNET_FRIENDS_write (struct GNUNET_FRIENDS_Writer *w,
106                       const struct GNUNET_PeerIdentity *friend_id);
107
108
109 #if 0                           /* keep Emacsens' auto-indent happy */
110 {
111 #endif
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif
117
118 /** @} */  /* end of group */