aboutsummaryrefslogtreecommitdiff
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.c167
1 files changed, 84 insertions, 83 deletions
diff --git a/src/conversation/plugin_gnsrecord_conversation.c b/src/conversation/plugin_gnsrecord_conversation.c
index adf397333..9f7299c15 100644
--- a/src/conversation/plugin_gnsrecord_conversation.c
+++ b/src/conversation/plugin_gnsrecord_conversation.c
@@ -44,51 +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 88
89 default: 89 default:
90 return NULL; 90 return NULL;
91 } 91 }
92} 92}
93 93
94 94
@@ -104,63 +104,63 @@ conversation_value_to_string(void *cls,
104 * @return #GNUNET_OK on success 104 * @return #GNUNET_OK on success
105 */ 105 */
106static int 106static int
107conversation_string_to_value(void *cls, 107conversation_string_to_value (void *cls,
108 uint32_t type, 108 uint32_t type,
109 const char *s, 109 const char *s,
110 void **data, 110 void **data,
111 size_t *data_size) 111 size_t *data_size)
112{ 112{
113 (void)cls; 113 (void) cls;
114 if (NULL == s) 114 if (NULL == s)
115 { 115 {
116 GNUNET_break(0); 116 GNUNET_break (0);
117 return GNUNET_SYSERR; 117 return GNUNET_SYSERR;
118 } 118 }
119 switch (type) 119 switch (type)
120 { 120 {
121 case GNUNET_GNSRECORD_TYPE_PHONE: 121 case GNUNET_GNSRECORD_TYPE_PHONE:
122 { 122 {
123 struct GNUNET_CONVERSATION_PhoneRecord *pr; 123 struct GNUNET_CONVERSATION_PhoneRecord *pr;
124 char line_port[103]; 124 char line_port[103];
125 const char *dash; 125 const char *dash;
126 struct GNUNET_PeerIdentity peer; 126 struct GNUNET_PeerIdentity peer;
127 127
128 if ((NULL == (dash = strchr(s, '-'))) || 128 if ((NULL == (dash = strchr (s, '-'))) ||
129 (1 != sscanf(s, "%103s-", line_port)) || 129 (1 != sscanf (s, "%103s-", line_port)) ||
130 (GNUNET_OK != 130 (GNUNET_OK !=
131 GNUNET_CRYPTO_eddsa_public_key_from_string(dash + 1, 131 GNUNET_CRYPTO_eddsa_public_key_from_string (dash + 1,
132 strlen(dash + 1), 132 strlen (dash + 1),
133 &peer.public_key))) 133 &peer.public_key)))
134 { 134 {
135 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 135 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
136 _("Unable to parse PHONE record `%s'\n"), 136 _ ("Unable to parse PHONE record `%s'\n"),
137 s); 137 s);
138 return GNUNET_SYSERR; 138 return GNUNET_SYSERR;
139 } 139 }
140 pr = GNUNET_new(struct GNUNET_CONVERSATION_PhoneRecord); 140 pr = GNUNET_new (struct GNUNET_CONVERSATION_PhoneRecord);
141 pr->version = htonl(1); 141 pr->version = htonl (1);
142 pr->reserved = htonl(0); 142 pr->reserved = htonl (0);
143 if (GNUNET_OK != 143 if (GNUNET_OK !=
144 GNUNET_STRINGS_string_to_data(line_port, 144 GNUNET_STRINGS_string_to_data (line_port,
145 strlen(line_port), 145 strlen (line_port),
146 &pr->line_port, 146 &pr->line_port,
147 sizeof(struct GNUNET_HashCode))) 147 sizeof(struct GNUNET_HashCode)))
148 { 148 {
149 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
150 _("Unable to parse PHONE record `%s'\n"), 150 _ ("Unable to parse PHONE record `%s'\n"),
151 s); 151 s);
152 GNUNET_free(pr); 152 GNUNET_free (pr);
153 return GNUNET_SYSERR; 153 return GNUNET_SYSERR;
154 } 154 }
155 pr->peer = peer; 155 pr->peer = peer;
156 *data = pr; 156 *data = pr;
157 *data_size = sizeof(struct GNUNET_CONVERSATION_PhoneRecord); 157 *data_size = sizeof(struct GNUNET_CONVERSATION_PhoneRecord);
158 return GNUNET_OK; 158 return GNUNET_OK;
159 } 159 }
160 160
161 default: 161 default:
162 return GNUNET_SYSERR; 162 return GNUNET_SYSERR;
163 } 163 }
164} 164}
165 165
166 166
@@ -168,7 +168,8 @@ conversation_string_to_value(void *cls,
168 * Mapping of record type numbers to human-readable 168 * Mapping of record type numbers to human-readable
169 * record type names. 169 * record type names.
170 */ 170 */
171static struct { 171static struct
172{
172 const char *name; 173 const char *name;
173 uint32_t number; 174 uint32_t number;
174} name_map[] = { 175} name_map[] = {
@@ -185,15 +186,15 @@ static struct {
185 * @return corresponding number, UINT32_MAX on error 186 * @return corresponding number, UINT32_MAX on error
186 */ 187 */
187static uint32_t 188static uint32_t
188conversation_typename_to_number(void *cls, 189conversation_typename_to_number (void *cls,
189 const char *gns_typename) 190 const char *gns_typename)
190{ 191{
191 unsigned int i; 192 unsigned int i;
192 193
193 (void)cls; 194 (void) cls;
194 i = 0; 195 i = 0;
195 while ((name_map[i].name != NULL) && 196 while ((name_map[i].name != NULL) &&
196 (0 != strcasecmp(gns_typename, name_map[i].name))) 197 (0 != strcasecmp (gns_typename, name_map[i].name)))
197 i++; 198 i++;
198 return name_map[i].number; 199 return name_map[i].number;
199} 200}
@@ -207,12 +208,12 @@ conversation_typename_to_number(void *cls,
207 * @return corresponding typestring, NULL on error 208 * @return corresponding typestring, NULL on error
208 */ 209 */
209static const char * 210static const char *
210conversation_number_to_typename(void *cls, 211conversation_number_to_typename (void *cls,
211 uint32_t type) 212 uint32_t type)
212{ 213{
213 unsigned int i; 214 unsigned int i;
214 215
215 (void)cls; 216 (void) cls;
216 i = 0; 217 i = 0;
217 while ((name_map[i].name != NULL) && 218 while ((name_map[i].name != NULL) &&
218 (type != name_map[i].number)) 219 (type != name_map[i].number))
@@ -228,12 +229,12 @@ conversation_number_to_typename(void *cls,
228 * @return the exported block API 229 * @return the exported block API
229 */ 230 */
230void * 231void *
231libgnunet_plugin_gnsrecord_conversation_init(void *cls) 232libgnunet_plugin_gnsrecord_conversation_init (void *cls)
232{ 233{
233 struct GNUNET_GNSRECORD_PluginFunctions *api; 234 struct GNUNET_GNSRECORD_PluginFunctions *api;
234 235
235 (void)cls; 236 (void) cls;
236 api = GNUNET_new(struct GNUNET_GNSRECORD_PluginFunctions); 237 api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions);
237 api->value_to_string = &conversation_value_to_string; 238 api->value_to_string = &conversation_value_to_string;
238 api->string_to_value = &conversation_string_to_value; 239 api->string_to_value = &conversation_string_to_value;
239 api->typename_to_number = &conversation_typename_to_number; 240 api->typename_to_number = &conversation_typename_to_number;
@@ -249,11 +250,11 @@ libgnunet_plugin_gnsrecord_conversation_init(void *cls)
249 * @return NULL 250 * @return NULL
250 */ 251 */
251void * 252void *
252libgnunet_plugin_gnsrecord_conversation_done(void *cls) 253libgnunet_plugin_gnsrecord_conversation_done (void *cls)
253{ 254{
254 struct GNUNET_GNSRECORD_PluginFunctions *api = cls; 255 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
255 256
256 GNUNET_free(api); 257 GNUNET_free (api);
257 return NULL; 258 return NULL;
258} 259}
259 260