diff options
Diffstat (limited to 'src/psycstore/psyc_util_lib.c')
-rw-r--r-- | src/psycstore/psyc_util_lib.c | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/src/psycstore/psyc_util_lib.c b/src/psycstore/psyc_util_lib.c index e45bcafb3..80e84f29c 100644 --- a/src/psycstore/psyc_util_lib.c +++ b/src/psycstore/psyc_util_lib.c | |||
@@ -198,11 +198,11 @@ GNUNET_PSYC_message_create (const char *method_name, | |||
198 | if (method_name_size == 1) | 198 | if (method_name_size == 1) |
199 | return NULL; | 199 | return NULL; |
200 | 200 | ||
201 | uint16_t msg_size = sizeof (*msg) /* header */ | 201 | uint16_t msg_size = sizeof (*msg) /* header */ |
202 | + sizeof (*pmeth) + method_name_size /* method */ | 202 | + sizeof (*pmeth) + method_name_size /* method */ |
203 | + env_size /* modifiers */ | 203 | + env_size /* modifiers */ |
204 | + ((0 < data_size) ? sizeof (*pmsg) + data_size : 0)/* data */ | 204 | + ((0 < data_size) ? sizeof (*pmsg) + data_size : 0) /* data */ |
205 | + sizeof (*pmsg); /* end of message */ | 205 | + sizeof (*pmsg); /* end of message */ |
206 | msg = GNUNET_malloc (msg_size); | 206 | msg = GNUNET_malloc (msg_size); |
207 | msg->header.size = htons (msg_size); | 207 | msg->header.size = htons (msg_size); |
208 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE); /* FIXME */ | 208 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE); /* FIXME */ |
@@ -225,6 +225,10 @@ GNUNET_PSYC_message_create (const char *method_name, | |||
225 | p += pmod->header.size; | 225 | p += pmod->header.size; |
226 | pmod->header.size = htons (pmod->header.size); | 226 | pmod->header.size = htons (pmod->header.size); |
227 | 227 | ||
228 | pmod->oper = mod->oper; | ||
229 | pmod->name_size = htons (mod_name_size); | ||
230 | pmod->value_size = htonl (mod->value_size); | ||
231 | |||
228 | memcpy (&pmod[1], mod->name, mod_name_size); | 232 | memcpy (&pmod[1], mod->name, mod_name_size); |
229 | if (0 < mod->value_size) | 233 | if (0 < mod->value_size) |
230 | memcpy ((char *) &pmod[1] + mod_name_size, mod->value, mod->value_size); | 234 | memcpy ((char *) &pmod[1] + mod_name_size, mod->value, mod->value_size); |
@@ -1192,9 +1196,9 @@ parse_message_part_cb (void *cls, | |||
1192 | pmod = (struct GNUNET_PSYC_MessageModifier *) msg; | 1196 | pmod = (struct GNUNET_PSYC_MessageModifier *) msg; |
1193 | 1197 | ||
1194 | const char *name = (const char *) &pmod[1]; | 1198 | const char *name = (const char *) &pmod[1]; |
1195 | const void *value = name + pmod->name_size; | 1199 | const void *value = name + ntohs (pmod->name_size); |
1196 | GNUNET_ENV_environment_add (pmc->env, pmod->oper, name, value, | 1200 | GNUNET_ENV_environment_add (pmc->env, pmod->oper, name, value, |
1197 | pmod->value_size); | 1201 | ntohl (pmod->value_size)); |
1198 | pmc->msg_state = GNUNET_PSYC_MESSAGE_STATE_MODIFIER; | 1202 | pmc->msg_state = GNUNET_PSYC_MESSAGE_STATE_MODIFIER; |
1199 | break; | 1203 | break; |
1200 | } | 1204 | } |
@@ -1233,7 +1237,7 @@ parse_message_part_cb (void *cls, | |||
1233 | * #GNUNET_SYSERR on parse error. | 1237 | * #GNUNET_SYSERR on parse error. |
1234 | */ | 1238 | */ |
1235 | int | 1239 | int |
1236 | GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_Message *msg, | 1240 | GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_MessageHeader *msg, |
1237 | const char **method_name, | 1241 | const char **method_name, |
1238 | struct GNUNET_ENV_Environment *env, | 1242 | struct GNUNET_ENV_Environment *env, |
1239 | const void **data, | 1243 | const void **data, |
@@ -1245,16 +1249,10 @@ GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_Message *msg, | |||
1245 | cls.data = data; | 1249 | cls.data = data; |
1246 | cls.data_size = data_size; | 1250 | cls.data_size = data_size; |
1247 | 1251 | ||
1248 | uint16_t msg_size = ntohs (msg->header.size); | ||
1249 | struct GNUNET_PSYC_MessageHeader * | ||
1250 | pmsg = GNUNET_malloc (sizeof (*pmsg) + msg_size - sizeof (*msg)); | ||
1251 | memcpy (&pmsg[1], &msg[1], msg_size - sizeof (*msg)); | ||
1252 | |||
1253 | struct GNUNET_PSYC_ReceiveHandle * | 1252 | struct GNUNET_PSYC_ReceiveHandle * |
1254 | recv = GNUNET_PSYC_receive_create (NULL, parse_message_part_cb, &cls); | 1253 | recv = GNUNET_PSYC_receive_create (NULL, parse_message_part_cb, &cls); |
1255 | GNUNET_PSYC_receive_message (recv, pmsg); | 1254 | GNUNET_PSYC_receive_message (recv, msg); |
1256 | GNUNET_PSYC_receive_destroy (recv); | 1255 | GNUNET_PSYC_receive_destroy (recv); |
1257 | GNUNET_free (pmsg); | ||
1258 | 1256 | ||
1259 | return (GNUNET_PSYC_MESSAGE_STATE_END == cls.msg_state) | 1257 | return (GNUNET_PSYC_MESSAGE_STATE_END == cls.msg_state) |
1260 | ? GNUNET_OK | 1258 | ? GNUNET_OK |
@@ -1284,7 +1282,7 @@ GNUNET_PSYC_message_header_init (struct GNUNET_PSYC_MessageHeader *pmsg, | |||
1284 | 1282 | ||
1285 | 1283 | ||
1286 | /** | 1284 | /** |
1287 | * Create a new PSYC message header from a multicast message for sending it to clients. | 1285 | * Create a new PSYC message header from a multicast message. |
1288 | */ | 1286 | */ |
1289 | struct GNUNET_PSYC_MessageHeader * | 1287 | struct GNUNET_PSYC_MessageHeader * |
1290 | GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg, | 1288 | GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg, |
@@ -1298,3 +1296,19 @@ GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader * | |||
1298 | GNUNET_PSYC_message_header_init (pmsg, mmsg, flags); | 1296 | GNUNET_PSYC_message_header_init (pmsg, mmsg, flags); |
1299 | return pmsg; | 1297 | return pmsg; |
1300 | } | 1298 | } |
1299 | |||
1300 | |||
1301 | /** | ||
1302 | * Create a new PSYC message header from a PSYC message. | ||
1303 | */ | ||
1304 | struct GNUNET_PSYC_MessageHeader * | ||
1305 | GNUNET_PSYC_message_header_create_from_psyc (const struct GNUNET_PSYC_Message *msg) | ||
1306 | { | ||
1307 | uint16_t msg_size = ntohs (msg->header.size); | ||
1308 | struct GNUNET_PSYC_MessageHeader * | ||
1309 | pmsg = GNUNET_malloc (sizeof (*pmsg) + msg_size - sizeof (*msg)); | ||
1310 | pmsg->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE); | ||
1311 | pmsg->header.size = htons (sizeof (*pmsg) + msg_size - sizeof (*msg)); | ||
1312 | memcpy (&pmsg[1], &msg[1], msg_size - sizeof (*msg)); | ||
1313 | return pmsg; | ||
1314 | } | ||