summaryrefslogtreecommitdiff
path: root/src/conversation/plugin_gnsrecord_conversation.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/conversation/plugin_gnsrecord_conversation.c')
-rw-r--r--src/conversation/plugin_gnsrecord_conversation.c188
1 files changed, 95 insertions, 93 deletions
diff --git a/src/conversation/plugin_gnsrecord_conversation.c b/src/conversation/plugin_gnsrecord_conversation.c
index 41c09ade9..adf397333 100644
--- a/src/conversation/plugin_gnsrecord_conversation.c
+++ b/src/conversation/plugin_gnsrecord_conversation.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file conversation/plugin_gnsrecord_conversation.c 22 * @file conversation/plugin_gnsrecord_conversation.c
@@ -44,50 +44,51 @@
44 * @return NULL on error, otherwise human-readable representation of the value 44 * @return NULL on error, otherwise human-readable representation of the value
45 */ 45 */
46static char * 46static char *
47conversation_value_to_string (void *cls, 47conversation_value_to_string(void *cls,
48 uint32_t type, 48 uint32_t type,
49 const void *data, 49 const void *data,
50 size_t data_size) 50 size_t data_size)
51{ 51{
52 char *s; 52 char *s;
53 53
54 (void) cls; 54 (void)cls;
55 switch (type) 55 switch (type)
56 { 56 {
57 case GNUNET_GNSRECORD_TYPE_PHONE: 57 case GNUNET_GNSRECORD_TYPE_PHONE:
58 { 58 {
59 const struct GNUNET_CONVERSATION_PhoneRecord *pr; 59 const struct GNUNET_CONVERSATION_PhoneRecord *pr;
60 char *ret; 60 char *ret;
61 char *pkey; 61 char *pkey;
62 62
63 if (data_size != sizeof (struct GNUNET_CONVERSATION_PhoneRecord)) 63 if (data_size != sizeof(struct GNUNET_CONVERSATION_PhoneRecord))
64 { 64 {
65 GNUNET_break_op (0); 65 GNUNET_break_op(0);
66 return NULL; 66 return NULL;
67 } 67 }
68 pr = data; 68 pr = data;
69 if (1 != ntohl (pr->version)) 69 if (1 != ntohl(pr->version))
70 { 70 {
71 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 71 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
72 _("PHONE version %u not supported\n"), 72 _("PHONE version %u not supported\n"),
73 ntohl (pr->version)); 73 ntohl(pr->version));
74 return NULL; 74 return NULL;
75 } 75 }
76 pkey = GNUNET_CRYPTO_eddsa_public_key_to_string (&pr->peer.public_key); 76 pkey = GNUNET_CRYPTO_eddsa_public_key_to_string(&pr->peer.public_key);
77 s = GNUNET_STRINGS_data_to_string_alloc (&pr->line_port, 77 s = GNUNET_STRINGS_data_to_string_alloc(&pr->line_port,
78 sizeof (struct GNUNET_HashCode)); 78 sizeof(struct GNUNET_HashCode));
79 79
80 GNUNET_asprintf (&ret, 80 GNUNET_asprintf(&ret,
81 "%s-%s", 81 "%s-%s",
82 s, 82 s,
83 pkey); 83 pkey);
84 GNUNET_free (s); 84 GNUNET_free(s);
85 GNUNET_free (pkey); 85 GNUNET_free(pkey);
86 return ret; 86 return ret;
87 } 87 }
88 default: 88
89 return NULL; 89 default:
90 } 90 return NULL;
91 }
91} 92}
92 93
93 94
@@ -103,62 +104,63 @@ conversation_value_to_string (void *cls,
103 * @return #GNUNET_OK on success 104 * @return #GNUNET_OK on success
104 */ 105 */
105static int 106static int
106conversation_string_to_value (void *cls, 107conversation_string_to_value(void *cls,
107 uint32_t type, 108 uint32_t type,
108 const char *s, 109 const char *s,
109 void **data, 110 void **data,
110 size_t *data_size) 111 size_t *data_size)
111{ 112{
112 (void) cls; 113 (void)cls;
113 if (NULL == s) 114 if (NULL == s)
114 { 115 {
115 GNUNET_break (0); 116 GNUNET_break(0);
116 return GNUNET_SYSERR; 117 return GNUNET_SYSERR;
117 } 118 }
118 switch (type) 119 switch (type)
119 { 120 {
120 case GNUNET_GNSRECORD_TYPE_PHONE: 121 case GNUNET_GNSRECORD_TYPE_PHONE:
121 { 122 {
122 struct GNUNET_CONVERSATION_PhoneRecord *pr; 123 struct GNUNET_CONVERSATION_PhoneRecord *pr;
123 char line_port[103]; 124 char line_port[103];
124 const char *dash; 125 const char *dash;
125 struct GNUNET_PeerIdentity peer; 126 struct GNUNET_PeerIdentity peer;
126 127
127 if ( (NULL == (dash = strchr (s, '-'))) || 128 if ((NULL == (dash = strchr(s, '-'))) ||
128 (1 != sscanf (s, "%103s-", line_port)) || 129 (1 != sscanf(s, "%103s-", line_port)) ||
129 (GNUNET_OK != 130 (GNUNET_OK !=
130 GNUNET_CRYPTO_eddsa_public_key_from_string (dash + 1, 131 GNUNET_CRYPTO_eddsa_public_key_from_string(dash + 1,
131 strlen (dash + 1), 132 strlen(dash + 1),
132 &peer.public_key)) ) 133 &peer.public_key)))
133 { 134 {
134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 135 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
135 _("Unable to parse PHONE record `%s'\n"), 136 _("Unable to parse PHONE record `%s'\n"),
136 s); 137 s);
137 return GNUNET_SYSERR; 138 return GNUNET_SYSERR;
138 } 139 }
139 pr = GNUNET_new (struct GNUNET_CONVERSATION_PhoneRecord); 140 pr = GNUNET_new(struct GNUNET_CONVERSATION_PhoneRecord);
140 pr->version = htonl (1); 141 pr->version = htonl(1);
141 pr->reserved = htonl (0); 142 pr->reserved = htonl(0);
142 if (GNUNET_OK != 143 if (GNUNET_OK !=
143 GNUNET_STRINGS_string_to_data (line_port, 144 GNUNET_STRINGS_string_to_data(line_port,
144 strlen (line_port), 145 strlen(line_port),
145 &pr->line_port, 146 &pr->line_port,
146 sizeof (struct GNUNET_HashCode))) 147 sizeof(struct GNUNET_HashCode)))
147 { 148 {
148 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 149 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
149 _("Unable to parse PHONE record `%s'\n"), 150 _("Unable to parse PHONE record `%s'\n"),
150 s); 151 s);
151 GNUNET_free (pr); 152 GNUNET_free(pr);
152 return GNUNET_SYSERR; 153 return GNUNET_SYSERR;
153 } 154 }
154 pr->peer = peer; 155 pr->peer = peer;
155 *data = pr; 156 *data = pr;
156 *data_size = sizeof (struct GNUNET_CONVERSATION_PhoneRecord); 157 *data_size = sizeof(struct GNUNET_CONVERSATION_PhoneRecord);
157 return GNUNET_OK; 158 return GNUNET_OK;
158 } 159 }
159 default: 160
160 return GNUNET_SYSERR; 161 default:
161 } 162 return GNUNET_SYSERR;
163 }
162} 164}
163 165
164 166
@@ -170,7 +172,7 @@ static struct {
170 const char *name; 172 const char *name;
171 uint32_t number; 173 uint32_t number;
172} name_map[] = { 174} name_map[] = {
173 { "PHONE", GNUNET_GNSRECORD_TYPE_PHONE }, 175 { "PHONE", GNUNET_GNSRECORD_TYPE_PHONE },
174 { NULL, UINT32_MAX } 176 { NULL, UINT32_MAX }
175}; 177};
176 178
@@ -183,15 +185,15 @@ static struct {
183 * @return corresponding number, UINT32_MAX on error 185 * @return corresponding number, UINT32_MAX on error
184 */ 186 */
185static uint32_t 187static uint32_t
186conversation_typename_to_number (void *cls, 188conversation_typename_to_number(void *cls,
187 const char *gns_typename) 189 const char *gns_typename)
188{ 190{
189 unsigned int i; 191 unsigned int i;
190 192
191 (void) cls; 193 (void)cls;
192 i=0; 194 i = 0;
193 while ( (name_map[i].name != NULL) && 195 while ((name_map[i].name != NULL) &&
194 (0 != strcasecmp (gns_typename, name_map[i].name)) ) 196 (0 != strcasecmp(gns_typename, name_map[i].name)))
195 i++; 197 i++;
196 return name_map[i].number; 198 return name_map[i].number;
197} 199}
@@ -205,15 +207,15 @@ conversation_typename_to_number (void *cls,
205 * @return corresponding typestring, NULL on error 207 * @return corresponding typestring, NULL on error
206 */ 208 */
207static const char * 209static const char *
208conversation_number_to_typename (void *cls, 210conversation_number_to_typename(void *cls,
209 uint32_t type) 211 uint32_t type)
210{ 212{
211 unsigned int i; 213 unsigned int i;
212 214
213 (void) cls; 215 (void)cls;
214 i=0; 216 i = 0;
215 while ( (name_map[i].name != NULL) && 217 while ((name_map[i].name != NULL) &&
216 (type != name_map[i].number) ) 218 (type != name_map[i].number))
217 i++; 219 i++;
218 return name_map[i].name; 220 return name_map[i].name;
219} 221}
@@ -226,12 +228,12 @@ conversation_number_to_typename (void *cls,
226 * @return the exported block API 228 * @return the exported block API
227 */ 229 */
228void * 230void *
229libgnunet_plugin_gnsrecord_conversation_init (void *cls) 231libgnunet_plugin_gnsrecord_conversation_init(void *cls)
230{ 232{
231 struct GNUNET_GNSRECORD_PluginFunctions *api; 233 struct GNUNET_GNSRECORD_PluginFunctions *api;
232 234
233 (void) cls; 235 (void)cls;
234 api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions); 236 api = GNUNET_new(struct GNUNET_GNSRECORD_PluginFunctions);
235 api->value_to_string = &conversation_value_to_string; 237 api->value_to_string = &conversation_value_to_string;
236 api->string_to_value = &conversation_string_to_value; 238 api->string_to_value = &conversation_string_to_value;
237 api->typename_to_number = &conversation_typename_to_number; 239 api->typename_to_number = &conversation_typename_to_number;
@@ -247,11 +249,11 @@ libgnunet_plugin_gnsrecord_conversation_init (void *cls)
247 * @return NULL 249 * @return NULL
248 */ 250 */
249void * 251void *
250libgnunet_plugin_gnsrecord_conversation_done (void *cls) 252libgnunet_plugin_gnsrecord_conversation_done(void *cls)
251{ 253{
252 struct GNUNET_GNSRECORD_PluginFunctions *api = cls; 254 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
253 255
254 GNUNET_free (api); 256 GNUNET_free(api);
255 return NULL; 257 return NULL;
256} 258}
257 259