- struct GNUNET_PSYCSTORE_OperationHandle *op;
- const struct OperationResult *opres;
- const struct CountersResult *cres;
- const struct FragmentResult *fres;
- const struct StateResult *sres;
- const char *str;
-
- if (NULL == msg)
- {
- reschedule_connect (h);
- return;
- }
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %d from PSYCstore service.\n",
- ntohs (msg->type));
- uint16_t size = ntohs (msg->size);
- uint16_t type = ntohs (msg->type);
- switch (type)
- {
- case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE:
- if (size < sizeof (struct OperationResult))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Received message of type %d with length %lu bytes. "
- "Expected >= %lu\n",
- type, size, sizeof (struct OperationResult));
- GNUNET_break (0);
- reschedule_connect (h);
- return;
- }
-
- opres = (const struct OperationResult *) msg;
- str = (const char *) &opres[1];
- if ( (size > sizeof (struct OperationResult)) &&
- ('\0' != str[size - sizeof (struct OperationResult) - 1]) )
- {
- GNUNET_break (0);
- reschedule_connect (h);
- return;
- }
- if (size == sizeof (struct OperationResult))
- str = "";
-
- op = find_op_by_id (h, GNUNET_ntohll (opres->op_id));
- if (NULL == op)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "No callback registered for operation with ID %" PRIu64 ".\n",
- type, GNUNET_ntohll (opres->op_id));
- }
- else
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received result message (type %d) with operation ID: %" PRIu64 "\n",
- type, op->op_id);
-
- int64_t result_code = GNUNET_ntohll (opres->result_code) + INT64_MIN;
- GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
- if (NULL != op->res_cb)
- {
- const struct StateSyncRequest *ssreq;
- switch (ntohs (op->msg->type))
- {
- case GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC:
- ssreq = (const struct StateSyncRequest *) op->msg;
- if (!(ssreq->flags & STATE_OP_LAST
- || GNUNET_OK != result_code))
- op->res_cb = NULL;
- break;
- }
- }
- if (NULL != op->res_cb)
- op->res_cb (op->cls, result_code, str, size - sizeof (*opres));
- GNUNET_free (op);
- }
- break;
-
- case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS:
- if (size != sizeof (struct CountersResult))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Received message of type %d with length %lu bytes. "
- "Expected %lu\n",
- type, size, sizeof (struct CountersResult));
- GNUNET_break (0);
- reschedule_connect (h);
- return;
- }
-
- cres = (const struct CountersResult *) msg;